|
It got stored in an instance of class WorkPackage which in turn is added to packagequeue
WorkPackage.h
class WorkPackage {
private:
WorkPackageState wp_state;
void (*m_action)(void*);
void* m_arguments = nullptr;
protected:
static int id;
public:
WorkPackage(){};
WorkPackage(void (*action)(void*), void* arguments);
void destroystack();
void execute();
static void setState(WorkPackageState wp_state);
WorkPackageState getState();
Stack Wp_localstack;
fcontext_t m_context;
int packageId;
};
Workpackage.cpp
WorkPackage::WorkPackage(void (*action)(void*), void* arguments) {
Wp_localstack.local_stack= Stack::make_stack();
m_action = action;
m_arguments = arguments;
Wp_localstack.local_stack = static_cast <char *>(Wp_localstack.local_stack) + 1000;
m_context = make_fcontext(Wp_localstack.local_stack, 1000, m_action);
wp_state = running;
packageId=++id;
}
WorkPackageState WorkPackage::getState() {
return state;
}
void WorkPackage::execute(int thread_id) {
m_action(m_arguments);
destroystack();
}
void WorkPackage::setState(WorkPackageState state) {
WorkPackageState new_state = state;
}
|
|
|
|
|
So, I guess, packagequeue is the place to find it.
|
|
|
|
|
Was just wandering if c++ is worth learning or is it outdated?
|
|
|
|
|
It depends. What do you want to do with it?
|
|
|
|
|
I want to make software in the windows enviornment
|
|
|
|
|
|
Mainly database type software.
|
|
|
|
|
In that case you'd probably be best to focus on what other languages you know. If you don't know any fitting languages then C# would be a good bet. For Windows software it'll be comparable (not as fast, but you the difference will be tiny) to C++ in terms of performance, but easier to write because there's a lot of simple tooling for C# User Interfaces and Database programming.
If you want to write some really high performance software, or if you want to just improve your understanding of how languages work at a lower level, then it's still worth
learning C++ (or C). In fact I'd still recommend learning it for your own education, but to be pragmatic if you want results, or a job you'll probably get a lot further with newer managed languages like C# - or web technologies.
|
|
|
|
|
Thanks for your input. I have a lot of thinking to do.
|
|
|
|
|
I think C++ is very much worth learning. However, that doesn't mean it's the best solution for every problem. For database front ends in Windows, C# tends to be a better choice. OTOH, I vastly prefer C++ and Qt over C# and WinForms/Xaml/whatever.
|
|
|
|
|
It is math worth learning?
Yes, I guess.
C++ is not outdated. It is difficult, it is a bit Byzantine.
|
|
|
|
|
Hi
I want to connect a number of sockets (2 or 3) on a port seems like the underlying Object of CAsynSocket is m_hSocket. That would lead me to believe that on the Client Side for Every
Client m_hSocket I would have to instantiate a CAsnycSocket class via new (on the heap) and do a Create and later connect ? It seems after the Create m_hSocket would have a value am I correct on this ?
Thanks
|
|
|
|
|
It's not completely clear what you're asking, but I can say that m_hSocket is the underlying SOCKET handle that the CAsyncSocket object encapsulates.
You are able to create a new CAsyncSocket object and then attach an existing SOCKET handle by using the Attach() method.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes that's what I was looking for so if I want to use 2 Different sockets I have to have two instances of CAsynSocket
In Addition If a wrapping CasynSockets in CWinThread Class when getting the OnConnect Notifcation Its is in The Context of the Main Thread so I would have to take that (Main Threads) m_hScoket and Attach to the one used by my CwinThread ? correct As I believe all CasynSocket notification are in the Context of the Main Thread
Thanks
|
|
|
|
|
|
#include<stdio.h>
#include<conio.h>
int main()
{
double width,hight,area;
printf("enter the value of width");
scanf("%f",&width);
printf("enter the vlaue of hight");
scanf("%f",&hight);
area=width*hight;
printf("area=%f",area);
return 0;
}
Why area=0.000 showing
|
|
|
|
|
I guess either width is zero or hight is zero or both are zero.
|
|
|
|
|
The format specifier you used in scanf is wrong: Change from
Quote: scanf("%f",&width); to
scanf("%lf",&width);
See scanf - C++ Reference[^]
Of course you need to make modify the other scanf call as well.
|
|
|
|
|
In constructor of my class WorkPackage , I am allocating a stack to each instance of workpackage and adding it to a queue. When a workpackage gets executed, the allocated stack get released in class destructor. The problem is that my destructor gets called before the execution of workpackage and program crashes with segmentation fault. I looked it up and thought that it is because of when i get the package from the queue:
PackageQueue.cpp
WorkPackage PackageQueue::GetWorkPackage(){
if (isEmpty())
{
return WorkPackage();
}
pthread_mutex_lock(&getlock);
WorkPackage data=WorkPackageQueue[front];
if (front == rear)
{
rear = -1;
front = -1;
}
else if (front == 0)
front = size-1;
else
front--;
pthread_mutex_unlock(&getlock);
return WorkPackage(data);
}
I created a copy contructor to allocate a new stack to the instance in case of deletion after GetWorkPackage function
WorkPackage::WorkPackage(const WorkPackage& rhs){
Wp_localstack.local_stack= Stack::make_stack();
m_action=rhs.m_action;
m_arguments=rhs.m_arguments;
}
But the problem is still there..Need hints to how can i do this correctly. I will provide more code if needed
modified 21-Sep-18 12:07pm.
|
|
|
|
|
What is rear?
What is front?
What is size?
What is data?
how is WorkPackage ctor defined?
|
|
|
|
|
rear and front are the indices of a circular array and size is queue length. data is the instance of the WorkPackage that is being retrieved and returned back for execution.
WorkPackage ctor
WorkPackage::WorkPackage(void (*action)(void*), void* arguments) {
Wp_localstack.local_stack= Stack::make_stack();
m_action = action;
m_arguments = arguments;
m_context = make_fcontext(Wp_localstack.local_stack, 1000, m_action);
WorkPackage dtor
WorkPackage::~WorkPackage(){
Stack::release(Wp_localstack.local_stack);
}
|
|
|
|
|
Then your code is doing something wrong, or in the wrong order. Your destructor needs a method of checking whether the stack has been correctly allocated before trying to release it.
|
|
|
|
|
Will need to look at the destructor code.
Since you're returning temporary objects, you could try changing the function signature to WorkPackage&& PackageQueue::GetWorkPackage
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Destructor is as follows.
WorkPackage::~WorkPackage(){
if (Wp_localstack.local_stack != nullptr)
{
Stack::release(Wp_localstack.local_stack);
}
}
and release() is follows.
void Stack::release(void * stack ){
int core_id= coreNumber::getInstance()->getCoreID();
WPManagerProviderSingleton& singletonObj =
WPManagerProviderSingleton::getInstance();
WorkPackageManager &wpm = singletonObj.getWpmInstance(core_id);
wpm.PerThreadMemPool.DeAllocate(stack);
}
|
|
|
|
|