2009-12-02 12:17:00

by Mai Daftedar

[permalink] [raw]
Subject: Inter Thread Coomunication

Hi all,
I have a question to ask I have two threads that have
messages(Structure with data) that should be passed between them.
After some googling I learnt that using queues and pipes are expensive
(effieciency wise) and that I should just pass in the parameters and
use mutex to protect shared data...
Can anyone add on to this tradeoff information

Note: Can you CC me in the reply


Thanks
Best Regards
Mai


2009-12-02 12:36:53

by Clemens Ladisch

[permalink] [raw]
Subject: Re: Inter Thread Coomunication

Mai Daftedar wrote:
> I have a question to ask I have two threads that have
> messages(Structure with data) that should be passed between them.
> After some googling I learnt that using queues and pipes are expensive
> (effieciency wise) and that I should just pass in the parameters and
> use mutex to protect shared data...

What is expensive is not necessarily the copying of the data into and
out of the pipe (this depends on the amount of data), but the system
calls necessary for this. If your threads use mutexes to wait for the
data, you have system calls anyway (actually going to sleep and waking
up cannot be handled in userspace), so there might not be any difference
one way or the other. The only way to find out is to test both
mechanisms.


HTH
Clemens

2009-12-02 17:20:28

by Stefan Richter

[permalink] [raw]
Subject: Re: Inter Thread Coomunication

Mai Daftedar wrote:
> After some googling I learnt that using queues and pipes are expensive
> (effieciency wise) and that I should just pass in the parameters and
> use mutex to protect shared data...
> Can anyone add on to this tradeoff information

The entire point of threads (in contrast to processes) is to share an
address space for convenience or/and performance. If a shared address
space is not really required, separate processes could be used instead
with the huge advantage of memory protection.
--
Stefan Richter
-=====-==--= ==-- ---=-
http://arcgraph.de/sr/