in reply to sharing (io::socket) objects with threads

that's a thrilling question, but i don't think your approach will work. because in principle it is not possible to share object references between threads. all shared data must be scalars. so maybe you're trying to catch the problem at the wrong end? if i understand you right, your main thread needs to know whether a child thread (one of the brains) closed the connection. the first idea that comes into my mind is: reverse the socket architecture. let the main thread listen and accept connections, not the brains. if this is a trivial proposal to you, there's maybe another thing possible, namely via localizing a hook for $SIG{__DIE__}. when a brain's socket closes the connection, this should be noticed. and the $SIG{__DIE__} handler should then put maybe the brain's identifier on a thread queue, which now effects the main thread to re-establish the connection.

i don't know ehether these remarks will be helpful, they just came into my mind.
cheers
TOD
--------------------------------
masses are the opiate for religion.
  • Comment on Re: sharing (io::socket) objects with threads

Replies are listed 'Best First'.
Re^2: sharing (io::socket) objects with threads
by BrowserUk (Patriarch) on May 17, 2007 at 03:27 UTC
    ... in principle it is not possible to share object references between threads ...

    But, IO::Socket::INET objects are not objects in the traditional perl sense in as much as they are actually globs. And, in common with traditional filehandles which are also globs, it is possible to derive a fileno from them, which is just a number (scalar) and can be passed between threads. Once you have the fileno in the thread, it is possible to dup a new glob from that fileno and so use that to access the socket.

    However, thread handles are true objects. So, whilst if you have the cpan version of threads, signalling between threads is possible, for your scheme to work, the child thread that is going to signal the main thread would require a thread handle in order to call the kill method upon it. How are you going to pass the thread handle (object) to the child thread(s) inorder to do this?

    It is possible through another round-about mechanism, but you surely haven't identified it.


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: sharing (io::socket) objects with threads
by chrism01 (Friar) on May 17, 2007 at 05:53 UTC
    FYI, you can thread-globally share complex structures eg HoHoH ... but you can only send scalars down a Thread::Queue.
    Although I think I once read that that (latter) was being worked on ...

    Cheers
    Chris

Re^2: sharing (io::socket) objects with threads
by bumby (Beadle) on May 17, 2007 at 11:47 UTC
    Letting the brains connect to the irc-proxy-thing instead of the reverse is brilliant! I've most have overseen this due to lack of sleep or something :) A simple yet brilliant solution! Thanks a lot! And thank you all others for your input!