N
NaeiKinDus
Hello, i'm trying to program a thread that would be locked (by a
mutex) and that would only be unlocked once that a function is done.
The purpose is to generate data, and unlock the mutex in order to
activate the thread once the data is generated.
step 1: initialize the mutex
mx (the mutex is part of the class "cl")
class Client
{
...
public:
pthread_mutex_t mx;
...
}
pthread_mutex_init(&cl->mx, NULL);
step 2:
as i'm calling a thread, i have to pass in param a structure :
struct S_PARAMS
{
...
pthread_mutex_t *mx;
...
} typedef T_PARAMS;
i create the thread and i copy the mutex in the param structure :
pthread_t thread;
params->mx = &cl->mx;
if ((thId = pthread_create(&thread, NULL, OBody::thFileSender, (void
*)params)) != 0)
{
THREAD NOT CREATED ... throw ...
}
else
{
}
mutex) and that would only be unlocked once that a function is done.
The purpose is to generate data, and unlock the mutex in order to
activate the thread once the data is generated.
step 1: initialize the mutex
mx (the mutex is part of the class "cl")
class Client
{
...
public:
pthread_mutex_t mx;
...
}
pthread_mutex_init(&cl->mx, NULL);
step 2:
as i'm calling a thread, i have to pass in param a structure :
struct S_PARAMS
{
...
pthread_mutex_t *mx;
...
} typedef T_PARAMS;
i create the thread and i copy the mutex in the param structure :
pthread_t thread;
params->mx = &cl->mx;
if ((thId = pthread_create(&thread, NULL, OBody::thFileSender, (void
*)params)) != 0)
{
THREAD NOT CREATED ... throw ...
}
else
{
}