TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Ruud Senden
from: Mike Bilow
date: 1995-01-10 09:27:00
subject: Unnamed pipes

Ruud Senden wrote in a message to All:

 RS> I'm writing a program with two threads. There are two
 RS> unnamed pipes, created with DosCreatePipe(), to communicate
 RS> between the threads. 

Maybe you need another thread.

 RS> One of the pipes is used to send commands from the main
 RS> thread to the other thread, the other one to send status
 RS> information from the other thread to the main thread.

Do you really need pipes to communicate between threads?  Pipes are usually
used to communicate between processes.  Threads of the same process can use
a block of ordinary memory and serialize access to it with a simple RAM
semaphore.

 RS> This works allright, except for one thing. When I do a
 RS> DosRead() when there is no command or status information on
 RS> a pipe, the DosRead()-call blocks until something is written
 RS> to the pipe.

Right: you need a thread that calls DosRead() and waits for it.  Only this
thread will be blocked while the pipe is empty, however.

 RS> Since I also have to do other things in both threads, I
 RS> don't want the DosRead()-call to block. 

Which is why you need an additional thread.

 RS> Is it possible to do this, or is there a call to check
 RS> whether there is some data waiting or not, so I can call
 RS> DosRead() only when there is data waiting? 

 RS> I hope somebody knows the answer, since I really need it for
 RS> my program. 

I suggest you re-examine your architecture.
 
-- Mike


---
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)
SEEN-BY: 12/2442 620/243 624/50 632/348 640/820 690/660 711/409 410 413 430
SEEN-BY: 711/807 808 809 934 942 949 712/353 515 713/888 800/1 7877/2809
@PATH: 323/107 150 3615/50 229/2 12/2442 711/409 808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.