开发者

How to block writing in pipes, until the read has taken place ? (in C)

I'm currently working on some C program, and I'd lik开发者_开发百科e to know if there's any chance to block writing in the writer process (until the read is done) ? i.e. I have 3 pipes between the parent process and the children processes (the parent writes and the children read), I'd like to let the parent to write only to the process that finishes its reading :)

I hope it's clear..

Thanks in advance.


bmargulies is correct. An alternative to creating a more complex protocol, however, would be to use multiple threads in the parent process -- one thread per child process. One thread might block due to a slow child, but the other threads could continue with their children. Depending on the details of your problem, this might solve it.


The kernel has a buffer limit for pipes, and writers will block if the buffer fills.

If you want to do this with your own message boundaries and not just based on the buffer size, then it's up to you to build a more complex protocol, such as having the reader block on a pipe going the other way before sending any more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜