Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: AnyEvent: How to protect critical sections?

by Corion (Pope)
on May 18, 2011 at 20:11 UTC ( #905556=note: print w/replies, xml ) Need Help??


in reply to Re^2: AnyEvent: How to protect critical sections?
in thread AnyEvent: How to protect critical sections?

It would seem to me that threads would "perfectly" do what's needed, by having the "timer" thread call sleep and the other thread do the HTTP fetching. Then, the critical HTTP fetch part will need to be protected by a critical section, for example a Thread::Semaphore, or by having the timer queue a request through a Thread::Queue. Depending on the nature of the problem, saintmike might want to avoid queueing more requests while one request (to the same resource) is already in progress.

Of course, real (OS) threads bring more concurrency problems than Coro brings. I'm not sure which bring be less problems, worrying about only ever calling ->recv in one place and keeping track of what timers to restart, or worrying about locking the proper sections of the code to make them single threaded or globally locked. Both are treatable problems, and neither seems like a clear winner over the other in this scenario.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-07-06 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?