Hi All.

>I have a program where two threads are handling one socket. One thread is
>reading and the other is writing to the socket.
>(using ActiveState Perl 5.8.8_822 on WinXP)
>However, the writer thread sometimes blocks for no apperent reason. I saw
>that the reader thead is using sysread, and got a suspicion that this
>sysread is blocking the writer thread from writing.
>
>Is it possible?

I read the archive to this mailing list, and saw a thread where one said
that Socket is not thread safe.
So my conclusion is that some mutex is protecting socket, the read operation
is catching it, and the write is waiting for it. Thus protecting me from
myself.

My solution was to replace the function that reads data from the socket in a
new version that peeks (using ioctl) to see how many bytes are available.
sleeps periodically until enough data arrive, and only then does the actual
read. 
This way the (supposed) mutex is not being hold most of the time, and the
writer thread is free to write whenever it wants.

Happy Coding,
Shmuel.


Reply via email to