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]
My other thinking is to try using a named pipe, have blob of logic 2 send some
data onto the pipe and go about it's merry way, where blob of logic 1, does a
select() on a shared file descriptor looking for a state change.
I haven't tried that before, but, I think it should work, however, I'd rather
not have the overhead of running a select on a shared fd on a named pipe, if a
manipulation of a pthread condition would allow for asynchronous signalling.
It would be highly cool if I didn't have to do polling in thread (n) for a
state change and could just rely on an asynchronous condition.
Am I barking up the wrong tree on that and is polling in one thread or another
unavoidable?
Trinkets/sweets to somebody who can find a non-polling solution
--
Bryan O'Donoghue
Embedded Software Engineer
Europlex Technologies Ltd
Clonshaugh Business & Technology Park
Dublin 17
Ireland
T:+353 (0) 1 2500500
F:+353 (0) 1 2500590
E:bryano at euoplex.ie
W:www.europlex.ie
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!