On Tue, 25 May 2004, Bryan O'Donoghue wrote:
>> case 1.
>> [blob of logic thread:1 does some stuff has some information which is shared
> between (n) threads]
> |
> |
> Time
> |
> |
> [blob of logic_2 thread:2 needs to know about stuff in blob of logic 1]
>> case 2.
>> Sometimes blob of logic 1 can happen *after* blob of logic 2.
>>> For case 2 a simple pthread_cond_time/dwait should suffice.
> For case 1, the asynchronous nature of the synchronisation violates that logic,
> so that
>> [blob of logic1 thread:1 pthread_cond_broadcast(something);]
> |
> |
> [blob of logic2 pthread_cond_wait(something) : blocks forever]
>> Which is bad.
>> Right now I'm having thread 1, wait for thread 2 to become ready, which also is
> bad.
>> [blob 1 : can be here pthread_cond_wait(something);]
> |
> time
> |
> [blob of logic 2 (thread_read==false){ nanosleep(for a while); } else {
> pthread_cond_broadcast(something);]
> |
> |
> time
> |
> [or blob of logic 1 can be here pthread_cond_wait]
>
I'm not sure I understand: is the problem that thread 1 might update twice
and at least one of threads 2 to n might miss a transition?
If so, one answer is to use two conditionals. As soon as thread 1
updates, it triggers cond1, and waits on cond2. The reading threads then
queue up to read the data (mutexes as appropriate), each modifying a
counter, and triggering cond2 when all threads have updated themselves.
Of course, I could be answering the wrong problem.
Ronan
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!