in reply to Keeping an INET socket inside a shared object
Hi s.fox,
I have to come up with the mostly undesireable meta question: What do you want to achieve sharing a socket between threads?
I'm asking because IO in general and IO over inet sockets is assumed to be slow. The complexity of threads is often introduced to have a solution for the blocking character of IO. So, I don't know what your use case is, but I would propose having one thread performing the whole IO for all other working/computing threads. In this case the one thread would try to read from the socket and put the result into a (dispatching) queue which gets read by the working threads and vice versa.
Even if you share the socket/fd between the threads you have to be very very careful in synchronizing the IO requests.
Have you some more isolated code to show your problem/use case?
Best regards
McA
|
|---|