[ILUG] Asynchronous thread ipc
Bryan O'Donoghue
bryano at europlex.ie
Tue May 25 17:34:19 IST 2004
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
More information about the ILUG
mailing list