* calling mutex_lock() twice from one thread
@ 2004-11-15 10:47 Bastian Voigt
2004-11-15 11:09 ` Nicolas EDEL
2004-11-17 6:11 ` Will Bryant
0 siblings, 2 replies; 4+ messages in thread
From: Bastian Voigt @ 2004-11-15 10:47 UTC (permalink / raw)
To: pthreads-win32
Dear list,
according to the documentation pthread_mutex_lock() assigns the mutex to
the calling thread, and if a different thread calls it again it will be
blocked.
In my scenario I want one thread to block itself, to be waked up later
by a signal handler. This does not work by simply calling mutex_lock()
twice, it does not block.
What can you recommend to achieve this? To be more concrete, I do the
following:
The main thread loads some configuration, then starts some worker
threads. After the worker threads are running I want the main thread to
sleep until a signal (Ctrl-C) arrives. Will it work better when using
semaphores?
Thanks for any hints!
Bastian Voigt
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calling mutex_lock() twice from one thread
2004-11-15 10:47 calling mutex_lock() twice from one thread Bastian Voigt
@ 2004-11-15 11:09 ` Nicolas EDEL
2004-11-17 6:11 ` Will Bryant
1 sibling, 0 replies; 4+ messages in thread
From: Nicolas EDEL @ 2004-11-15 11:09 UTC (permalink / raw)
To: Bastian Voigt; +Cc: pthreads-win32
Bastian Voigt wrote:
> Dear list,
>
> according to the documentation pthread_mutex_lock() assigns the mutex to
> the calling thread, and if a different thread calls it again it will be
> blocked.
>
> In my scenario I want one thread to block itself, to be waked up later
> by a signal handler. This does not work by simply calling mutex_lock()
> twice, it does not block.
>
> What can you recommend to achieve this? To be more concrete, I do the
> following:
>
> The main thread loads some configuration, then starts some worker
> threads. After the worker threads are running I want the main thread to
> sleep until a signal (Ctrl-C) arrives. Will it work better when using
> semaphores?
>
> Thanks for any hints!
>
> Bastian Voigt
hi,
maybe you should have a look at the pthread_cond_t doc & usage.
regards
--N
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calling mutex_lock() twice from one thread
2004-11-15 10:47 calling mutex_lock() twice from one thread Bastian Voigt
2004-11-15 11:09 ` Nicolas EDEL
@ 2004-11-17 6:11 ` Will Bryant
2004-11-17 7:51 ` Bastian Voigt
1 sibling, 1 reply; 4+ messages in thread
From: Will Bryant @ 2004-11-17 6:11 UTC (permalink / raw)
To: Bastian Voigt, pthreads-win32
Bastian Voigt wrote:
> The main thread loads some configuration, then starts some worker
> threads. After the worker threads are running I want the main thread
> to sleep until a signal (Ctrl-C) arrives. Will it work better when
> using semaphores?
Yes, aside from the fact that you want non-recursive locks, semaphores
are the _only_ synchronization primitive that can be used from inside
signal handlers. Note that condition variables most definitely cannot
be signalled from inside a signal handler - that will break - badly - on
most unix platforms.
--
Will Bryant
Systems Architect, eCOSM.
Phone +64 3 365 4176 | Mobile +64 21 655 443
http://www.ecosm.com/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calling mutex_lock() twice from one thread
2004-11-17 6:11 ` Will Bryant
@ 2004-11-17 7:51 ` Bastian Voigt
0 siblings, 0 replies; 4+ messages in thread
From: Bastian Voigt @ 2004-11-17 7:51 UTC (permalink / raw)
To: pthreads-win32
Will Bryant wrote:
> Yes, aside from the fact that you want non-recursive locks, semaphores
> are the _only_ synchronization primitive that can be used from inside
> signal handlers. Note that condition variables most definitely cannot
> be signalled from inside a signal handler - that will break - badly - on
> most unix platforms.
Thank you very much. That really helps.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-11-17 7:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-15 10:47 calling mutex_lock() twice from one thread Bastian Voigt
2004-11-15 11:09 ` Nicolas EDEL
2004-11-17 6:11 ` Will Bryant
2004-11-17 7:51 ` Bastian Voigt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).