Inter thread communication using pipes?

Hi ,
Does anyone know if Pipes can be used for communication between threads.

I guess we can use them… but was wondering about the performance.
The way I plan to use them is to have two pairs of pipes opened to make
full duplex
communication using one for reading and the other for writing. I didn’t
want to get into
the mutex and condition wait mechanisms.

Thanks
venks

Hi ,
Does anyone know if Pipes can be used for communication between threads.

I guess we can use them… but was wondering about the performance.
The way I plan to use them is to have two pairs of pipes opened to make
full duplex
communication using one for reading and the other for writing. I didn’t
want to get into
the mutex and condition wait mechanisms.

Sure, it’s not portable, but it will work.
If you have only a single reader and writer, a ring buffer is faster:

(untested pseudo-code)

array messages queue[];
int head, tail;
int queue_size;

reader (Note: this code doesn’t block - you’ll need a mutex for that):
if ( head != tail ) {
message = queue[tail];
tail = (tail+1)%queue_size;
}

writer:
queue[head] = message
head = (head+1)%queue_size;

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

Does anyone know if Pipes can be used for communication between threads.

I guess we can use them… but was wondering about the performance.

You understand this is a very platform-specific method of communication?
That means you are using a portable library (SDL) and then using
nonportable methods (pipes) to pass data between threads.

On the assumption that you’re really set on using them, use the
socketpair() system call to create a full-duplex pipe for use. Since the
data is only moving internally the performace is pretty darned good.
Maybe not as good as shared memory segments but it will run circles around
any graphics processing your application is doing.

Paul Braman
@Paul_BramanOn Mon, 7 Feb 2000, Venkatesh Natarajan wrote: