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

Re^2: ithreads, locks, shared data: is that OK?

by bliako (Parson)
on Sep 20, 2018 at 09:35 UTC ( #1222701=note: print w/replies, xml ) Need Help??


in reply to Re: ithreads, locks, shared data: is that OK?
in thread ithreads, locks, shared data: is that OK?

Sorry, I wanted to post the complete program.

Regarding the locking of Thread::Queue, I saw in their doc (Advanced Methods) how to lock queue. And decided to do the same. Do you know what is the purpose of the lock() in the manual?

As for the dictionary, thanks for the suggestion. I will investigate if the performance is OK.

So, thanks for the info and sorry for the long code, bliako.

  • Comment on Re^2: ithreads, locks, shared data: is that OK?

Replies are listed 'Best First'.
Re^3: ithreads, locks, shared data: is that OK?
by choroba (Archbishop) on Sep 20, 2018 at 09:38 UTC
    You don't need to lock the queue for enqueue and dequeue. You need it for peek, but why do you need peek? Enqueue and dequeue should be all you need :-)

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      got it thanks

      well, I need to peek() because one of my queues is not a "work" queue: i.e. enqueue() any data for processing by the thread. Rather, it is a list of all data (=dictionary words) currently being processed by threads (call it CWq queue). And another one is a list of all the words that already have been processed and done with (call it REq). So, before a thread processes word W, it must peek() queue CWq and see if W is in there. In which case it will skip it. Also it will skip if the word is in the REq, so another peek() there.

      Ideally CWq and REq should have been a hash but I find sharing a hash way too complicated than lock() and peek() a queue. A queue is definetely a weird hammer for that sort of nail. Any suggestions?

        I don't fully understand your workflow. If you want to process each word just once, create a thread that keeps a hash of the processed words and ask it before sending any word forward maybe?

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2020-01-18 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?