in reply to Re^3: Thread-safe modules and callbacks
in thread Thread-safe modules and callbacks

It's the 2nd case
Basically it's for a ipc through messages, in this case we'd have no-threaded process that uses the provided module. The module creates itself the thread and calls the callback for each message.
Basically it'll just manage strings as messages are strings, the most common behaviour would be to add the messages to a queue(that must be shared with the rest of the process, this is part of the problem) but the user might do other operations on the callback that use external variables.
So I really can't see a way of isolating the user from the thread system. We'd need to share every variable at the callback and every variable at the program(to be acesible from the callback) dymanically. I don't see the way, but just wondering....
Thanks
  • Comment on Re^4: Thread-safe modules and callbacks

Replies are listed 'Best First'.
Re^5: Thread-safe modules and callbacks
by BrowserUk (Patriarch) on May 10, 2008 at 13:52 UTC
    So I really can't see a way of isolating the user from the thread system. We'd need to share every variable at the callback and every variable at the program(to be acesible from the callback) dymanically.

    You're saying that you want to share all user code variables with all the threads, but without the user being concerned with the fact that they are shared, nor even knowing that they are using threads at all. Sorry, but that simply isn't possible. Not with any technology I am aware of, and certainly not with Perl.

    That said, I think this is a genuine case of the notorious XY problem. That is, you are asking how to implement what you perceive is the solution to the problem, rather than describing the problem and asking how it might be solved.

    If you would start by posting a simple worked example of an application, from the user perspective, that talks to two servers (or clients) and demonstrates how you envisage them interacting, then an alternative solution may be apparent. Just describe the application, and how you would like the user visible API to e used to fulfill that application and forget about how it might be implemented. From that we'll see if we can't come up with something that could work for you.


    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.
      Ok, here is the way it works at this moment.
      #!/usr/bin/perl use strict; use warnings; use Server; my $Listener = new Server(2222,\&messageHandler); $Listener->Start(); my @messages; push(@messages,"something"); sub messageHandler{ my $message = shift; my $peer = shift; chomp($message); push(@messages,$message); print "Inside callback @messages\n"; } while(1){ print "Outside callback @messages\n"; sleep(1); }
      Start sending messages
      saladino@Zack$ perl pgenerator.pl Listening Outside callback something Outside callback something Outside callback something Outside callback something Outside callback something Outside callback something Outside callback something Outside callback something Outside callback something Inside callback sdfas Outside callback something Inside callback sdfas safsadf Outside callback something Outside callback something Inside callback sdfas safsadf sadfsasafsa Outside callback something Outside callback something Outside callback something
      If i share @messages, it would work, but that doesn't abstract the client from threads

        You're still demonstrating something that shows no advantage to using threads.

        If the users callback is simply going to push inbound messages from a single source onto an array. And the main thread is just going to access them. What is having the point/advantage of using a thread in the first place?

        To be more explicit. What information needs to be shared between which threads? And why?


        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.