[libevfibers] Re: interfacing with external resource callbacks

  • From: Konstantin Olkhovskiy <lupus@xxxxxxxxxx>
  • To: libevfibers@xxxxxxxxxxxxx
  • Date: Fri, 29 May 2015 20:01:45 +0300


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).

Other related posts: