http://qs321.pair.com?node_id=905551


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

He might not want the extra dependency on Coro, and the windows emulation code in perl (the other "threads") is of little help in this case-
  • Comment on Re^2: AnyEvent: How to protect critical sections?

Replies are listed 'Best First'.
Re^3: AnyEvent: How to protect critical sections?
by Corion (Patriarch) on May 18, 2011 at 20:11 UTC

    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.