Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: need a thread to wait until a buffer is full.

by archfool (Monk)
on Jul 25, 2007 at 02:42 UTC ( [id://628611]=note: print w/replies, xml ) Need Help??


in reply to Re: need a thread to wait until a buffer is full.
in thread need a thread to wait until a buffer is full.

The things you put in a Thread::Queue don't need to be shared. Just the Thread::Queue itself.
  • Comment on Re^2: need a thread to wait until a buffer is full.

Replies are listed 'Best First'.
Re^3: need a thread to wait until a buffer is full.
by BrowserUk (Patriarch) on Jul 25, 2007 at 05:32 UTC
    he things you put in a Thread::Queue don't need to be shared. Just the Thread::Queue itself.

    They do if you want access them from more than one thread. Note that I am passing a reference to the shared buffer via the Queue, not the buffer itself.

    If you can see a better way of coding this, please post your code.


    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.
      The buffer contains raw binary data that can be anything, it is directly read from the hd, the other thread will read a block from the hd and put it into the buffer. I know that lock goes away after the scope {}. my problem is how do I ensure the thread that fills the buffer locks it before the thread that created it checks it. I do not want my thread that uses the buffer to lock it so that it can check if it is filled, then have the thing that fills it sit there and wait since the thread that uses it has the lock.... essentially my question is this: If I use lock in a loop, then when the loop goes to the next iteration is that going out of scope and releasing the lock, or is it holding the lock since it is one loop?

      --------------------------------------

      I would rather take 30 minutes to re-invent the wheel then take 30 days to learn how to use someone else's. Before pestering me about my re-invention prepare to defend yourself with a way of learning how to use the wheel in less time than it takes for me to make one, one that I might add is specialized to my specific task!

        Why don't you design to avoid the locking altogether? Just have 2 buffers, one in each thread. Have the first thread signal the second to start filling it's buffer, and when it's done, set a shared variable to "filled". Have your first thread watch the shared variable, and when it says "filled", copy the buffer and reset.

        I'm sure there probably is a way to avoid the copying, by sharing the buffer too, but unless there are performance issues with the extra in-memory copy, it's safer and easier to keep things separate.


        I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-25 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found