thanks, yes i have a lock for the loop (i focused too much on the timer that i forgot to mention it in the explanation), i lock that lock just before calling ev_timer_again and realising it just after, right now i only one the thread running the ev_run and one database thread, i m going to check the code because i might be forgetting to acquire the loop lock somewhere then. i ll let you know in a little while.
On 13 June 2011 14:01, Marc Lehmann <[email protected]> wrote: > On Mon, Jun 13, 2011 at 08:38:42AM -0600, Juan Pablo L > <[email protected]> wrote: >> (not from any callback), i m calling from another thread. >> i m calling ev_break from another thread. > > As was already pointed out,t hat is your problem. When using threads, you > have to take care of threads executing in paralle or switching at any time, > so when you access a shared resource (such as the event loop) you have to use > a mutex. > > On Mon, Jun 13, 2011 at 12:09:52PM -0600, Juan Pablo L > <[email protected]> wrote: >> yes, i m using mutexes for the timers, so when i modify and reset a > > The fact that you are in ev_loop in one thread and calling ev_timer_again > in another thread instantly tells me that you are not using mutexes to > lock the loop. > > With threads, you have to lock *every* shared resource, that includes the > loop. > >> Maybe what i m trying to do is estrange but here it goes, i m doing a >> database pool and the timers are one per database connection, so as to > > I can't verify whether this approach is corretc or not, but you basically > have these choices: > > - do not access the event loop, except maybe via ev_async watchers. > this might be easier than it sounds: maybe you can use a threadpool. > - do proper locking (and use ev_async watchers to wake up the event loop > if it is currently blocked). > > Both approaches are documented in the documentation - search for "thread" > and "locking" and you will find an example for the latter, search for > ev_async and you find plenty of documentation for async watchers. > >> message in the timeout callback so i m expecting to see the message >> (callback being called) every second for as long as the connection is >> held by the database thread. > > As always with threads, you need to use locking so that not two threads > access/modify the same data structure at the same time. In addition to > that, you need a way to wake up the event loop blocked in another thread, > and you are there. > > -- > The choice of a Deliantra, the free code+content MORPG > -----==- _GNU_ http://www.deliantra.net > ----==-- _ generation > ---==---(_)__ __ ____ __ Marc Lehmann > --==---/ / _ \/ // /\ \/ / [email protected] > -=====/_/_//_/\_,_/ /_/\_\ > _______________________________________________ libev mailing list [email protected] http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev
