problem mutex-thread "Unlocking mutex owned by another thread ???"

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
{

}
 
J

Jack Klein

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.

This group discusses the standard C++ language, which does not define
either threads or mutexes.

[snip]

pthread_mutex_t mx;

pthreads are a system-specific extension and off-topic here.

You need to ask this question in a newsgroup that supports your
particular operating system. Or perhaps
Not in a language group.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top