I have some problems with making threads in Linux
This is the situation:
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
class myclass
{
private:
char stack[ 1024*10 ];
public:
void myclone( void );
void thread_func( void );
int volatile somevar;
};
static void LaunchThread( myclass *A )
{
A->thread_func();
};
void myclass::myclone( void )
{
clone( (int(*)(void*))&LaunchThread, &stack, CLONE_VM|CLONE_FS|CLONE_FILES, this );
}
void myclass::thread_func( void )
{
somevar = 0;
while( somevar == 0 )
{
//do something
}
// write something
}
myclass A, B;
int main( void )
{
A->myclone();
B->myclone();
A->somevar = 1;
B->somevar = 1;
return 0;
}
and there the mess begins A->clone() does launch A->thread_func() , B->clone() does not; A->somevar = 1 as well as the same with B does not terminate the cycle in thread_func(); i've searched the internet for a solution but did not find one.
Could some one tell me the correct way ( or there is my mistake here ) to do multithreading with classes in Linux, pleaaaasee
This is the situation:
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
class myclass
{
private:
char stack[ 1024*10 ];
public:
void myclone( void );
void thread_func( void );
int volatile somevar;
};
static void LaunchThread( myclass *A )
{
A->thread_func();
};
void myclass::myclone( void )
{
clone( (int(*)(void*))&LaunchThread, &stack, CLONE_VM|CLONE_FS|CLONE_FILES, this );
}
void myclass::thread_func( void )
{
somevar = 0;
while( somevar == 0 )
{
//do something
}
// write something
}
myclass A, B;
int main( void )
{
A->myclone();
B->myclone();
A->somevar = 1;
B->somevar = 1;
return 0;
}
and there the mess begins A->clone() does launch A->thread_func() , B->clone() does not; A->somevar = 1 as well as the same with B does not terminate the cycle in thread_func(); i've searched the internet for a solution but did not find one.
Could some one tell me the correct way ( or there is my mistake here ) to do multithreading with classes in Linux, pleaaaasee
