[libevfibers] Re: interfacing with external resource callbacks

  • From: Phil Carns <carns@xxxxxxxxxxx>
  • To: <libevfibers@xxxxxxxxxxxxx>
  • Date: Fri, 29 May 2015 15:08:14 -0400

On 05/29/2015 01:01 PM, Konstantin Olkhovskiy wrote:


That's perfect. Is it safe to declare the condition variable (and
corresponding mutex) on the stack of the fiber/function that calls
fbr_cond_wait() as long as I make sure that it doesn't go out of
scope before the resource callback issues the signal()?


Yeah, sure.

I'm comfortable with that, but just to clarify for my own
understanding: the reason you wouldn't use the cond variable
approach in this case is because of the possibility for the two
threads to race in modifying the internal wait list for the fbr
cond variable, right?


Yes, libevfibers itself is not thread safe, but you can have several contexts
(or fiber schedulers) running in different threads and using different libev
loops. Quickly looking at the code, I think there shouldn't be any race in
your case, but better don't do that. May be I will reconsider fbr_cond_signal
to be officially thread safe later (and fbr_cond_broadcast as well).

Ok, that makes sense. Thanks for the clarification.

-Phil

Other related posts: