I can't tell from your code if this advice is applicable, but threads that read or write from sockets should do NOTHING else. Read threads should queue their data, and write threads should be fed from a data queue. Reading and writing should be done in different threads.
Otherwise, the unpredictability of buffering and actual data transmission guarantees that unexpected stall conditions will occur.