in reply to Can I/O operations on the same IO::Socket be executed in different threads?

Threads may share a socket or file descriptor all right, but you probably ought to use low-level Socket module if that is your intent. Any issues with the resource sharing (synchronization, locking, state logic, teardown, and so on) are solely your responsibility. This precludes the use of protocol layers such as SSL.

  • Comment on Re: Can I/O operations on the same IO::Socket be executed in different threads?

Replies are listed 'Best First'.
Re^2: Can I/O operations on the same IO::Socket be executed in different threads?
by BrowserUk (Patriarch) on May 12, 2015 at 08:16 UTC
    Threads may share a socket or file descriptor all right

    Care to back that assertion up with some code that does it; and does something useful?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      I can't speak for the AM, but several years ago I wrote some C code on Linux that shared a socket between 2 threads, one reading, one writing (like what the OP wants to do). It worked for me. I don't know if this would work on MS Windows.

        I wrote some C code

        I once wrote a program that allowed the computer to play solitaire, but there is a difference between what is feasible, and what is logical and sensible.

        There is simply no logical reason to split the reading from and writing to, one end of a single socket, between threads.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      Any threaded code that spits debugging info (say), ought to satisfy your stipulation. (Although technically, a pty is not a socket. But then again, one might redirect the output.)

        Show us!


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
        In the absence of evidence, opinion is indistinguishable from prejudice.