Home > Archive > Unix Programming > December 2006 > read/write block. I hope I worded this question correctly.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
read/write block. I hope I worded this question correctly.
|
|
| K-mart Cashier 2006-12-16, 7:06 pm |
| Say I have the following code snippet:
while ( (n = read(STDIN_FILENO, buf, BUFSIZE) ) > 0)
if(write(STDOUT_FILENO, buf, n) != n)
When write() gets executed, does the read() function get blocked until
write()
is finshed?
Chad
| |
| Jens Thoms Toerring 2006-12-16, 7:06 pm |
| K-mart Cashier <cdalten@gmail.com> wrote:
> Say I have the following code snippet:
> while ( (n = read(STDIN_FILENO, buf, BUFSIZE) ) > 0)
> if(write(STDOUT_FILENO, buf, n) != n)
> When write() gets executed, does the read() function get blocked until
> write() is finshed?
Maybe be I misunderstand your question, but while the program is in
the write() function the read() function isn't being executing at all,
so it can't be called being blocked. So your program is definitely not
reading anything while it's busy with write() (unless you have snipped
a bit too much and the lines are from different places and e.g. the
first line is executed by one thread and the second line by a different
thread).
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
| |
| loic-dev@gmx.net 2006-12-16, 7:06 pm |
| Hello Chad,
> Say I have the following code snippet:
>
> while ( (n = read(STDIN_FILENO, buf, BUFSIZE) ) > 0)
> if(write(STDOUT_FILENO, buf, n) != n)
>
>
> When write() gets executed, does the read() function get blocked until
> write()
> is finshed?
The /read()/ will be executed only after the /write()/ has completed.
Brgds,
Loic.
| |
| K-mart Cashier 2006-12-16, 7:06 pm |
|
Jens Thoms Toerring wrote:
> K-mart Cashier <cdalten@gmail.com> wrote:
>
>
>
>
> Maybe be I misunderstand your question, but while the program is in
> the write() function the read() function isn't being executing at all,
> so it can't be called being blocked. So your program is definitely not
> reading anything while it's busy with write() (unless you have snipped
> a bit too much and the lines are from different places and e.g. the
> first line is executed by one thread and the second line by a different
> thread).
My written communication skills sort of suck. Anyhow, you answered what
I meant to ask. I'm glad you are a good mind reader when it comes to
poorly worded questions.
Chad
|
|
|
|
|