Skip to contentSkip to conversation

Inter Thread Coomunication

DISCUSSION Mai Daftedar 3 participants 3 messages Dec 2, 2009

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 5 lines · Mai Daftedar

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

#2 lore raw
In reply to Mai Daftedar
Quoted 4 lines · Mai Daftedar

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.

Signature · 3 lines
Stefan Richter
-=====-==--= ==-- ---=-
http://arcgraph.de/sr/