in reply to Threading problem with IO::Socket

The first thing worth noting is that sockets, like other handles (STDIN, STDOUT etc) are process global enitities, and are therefore implicitly and inexorably shared by all threads within a process.

The caveat is that when you use a class like IO::Socket to manage a process global resource, it uses memory to retain state. This memory is not implicitly shared. Further, the mechanism by which perl locates methods applicable to objects is through the blessing of the object handle which is a memory reference. The problem here is that even if the routines that implement those methods are re-entrent, unless the state represented by the object handle are themselves correctly shared (and are shareable!), then invoking methods across threads is going to give rise to problems. This is why objects are not shareable.

The upshot is, that the main problem of your code lies in the concepts underlying it. Why do you want to share a process global resource between threads? What are you trying to achieve? Whatever it is can probably be achieved, but it would take and understanding of your goals before the 'right' approach to the problem could be discovered.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller