Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am doing multithreaded programming in perl involving sockets. I am using a IO::Select variable as a shared variable. I am declaring it as.. use threads; use threads::shared; my $write_set : shared; $write_set = new IO::Select(); I will be using this to keep a list of connected client's sockets. I have a thread which will be accepting for client connections. So, in the thread ,when i get a client's request connection, i try to add socket handle to $write_set. $write_set->add($new_sock); The following error is coming. Invalid value for shared scalar at abc.pl line 63. Can any one help me on this regard.

Replies are listed 'Best First'.
Re: Invalid value for shared scalar error with shared class object
by cdarke (Prior) on Mar 18, 2009 at 13:40 UTC
    $write_set is a scalar - a reference to an IO:Select object. Making that scalar sharable does not make the thing it references sharable.

    Your post is remarkably similar to this which dates from June 2005. It looks like you cut and pasted it. How come?
Re: Invalid value for shared scalar error with shared class object
by BrowserUk (Patriarch) on Mar 18, 2009 at 13:41 UTC

    You cannot share (standard perl) blessed references (objects) between threads using threads::shared.

    However, recent version of threads::shared export another version of bless which does allow the sharing of objects.

    But it's not clear to me how you would go about re-blessing an object returned by a pre-existing module that does not use the shareable version of bless?

    See yourperl/html/lib/threads/shared.html#objects for a little more info.


    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: Invalid value for shared scalar error with shared class object
by Anonymous Monk on Mar 18, 2009 at 13:36 UTC