Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Do you know where your variables are?
 
PerlMonks  

Re: Synchronising threads with signals (or not)

by sundialsvc4 (Monsignor)
on Feb 22, 2013 at 20:56 UTC ( #1020227=note: print w/ replies, xml ) Need Help??


in reply to Synchronising threads with signals (or not)

What’s missing from your sketchup is how the two threads are intended to work together.   Do they work “together,” e.g. one is capturing data that the other one is producing?   That’s going to make a tremendous difference in how the whole thing should be properly set-up.

But in any case ... threads shouldn’t have tight timing-expectations like you describe.   If a thread is consuming something, let it read from a queue (e.g. Thread::Queue), simply blocking on the read if there is nothing there to read yet.   Ditto, let a producer-thread push data onto such a queue and keep going on its merry way.   If someone needs to monitor the status of something, push status-messages onto some queue for the monitor to remove.   If it’s time to shut-down the child threads, send a “please shut down” command-message to that child’s queue.

Queues act like flexible, stretchy hoses, buffering away the timing dependencies and letting the threads run efficiently at full speed with little or no need to “rendezvous” with one another.


Comment on Re: Synchronising threads with signals (or not)
Re^2: Synchronising threads with signals (or not)
by BrowserUk (Pope) on Feb 22, 2013 at 21:03 UTC

    How can a queue help you coordinate a music recorder to record a music player?

    It cannot!


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Obviously, that was my question, and a very good question it was:   how is a music-recorder thread to be related to a music-player thread?   What are the two processes doing together, such that they need to sychronize?   A recorder certainly is a data-gatherer and a player is a data-consumer, but the two activities don’t particularly sound to me as something that would be synchronized in a producer/consumer relationship.   And that is what has merely triggered idle speculation in both of us.

      Subprocesses, such as “user-interface controls player and recorder threads,” are in my experience most-commonly handled with signals to the effect that “your status has changed ... you need to do something differently now ... now wake up, or stop what you’re doing, and go find out what it is.”   Condition variables, on the other hand, are inherently a synchronization mechanism.   Which is why I asked for clarification ... and perhaps also why the OP has now abandoned the question.

        How can a queue help you coordinate a music recorder to record a music player?
        Obviously, that was my question,

        What garbage you speak. You were the one that suggested using a queue. You were not questioning its applicability to the OPs problem.

        “user-interface controls

        No one mention "user interface controls". You are just making it up as you go along. As per normal. Pathetic!


        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".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020227]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-04-20 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (487 votes), past polls