Aha! Thanks, that was it.
I thought libev internally may get loop from watcher and vice-versa, but
looks like loop may have multiple watchers of same type as well as
single watcher may be assigned to multiple loops. That explains why
ev_async_send requires both loop and watcher, this was surprise for me...
On 06/29/13 17:27, 马承珂 wrote:
line 25:
ev_async_send (dyn_loop, &mysig);
should be:
ev_async_send (dyn_loop, &async_w);
mysig is a useless var.
At 2013-06-30 05:50:37,trafdev <[email protected]> wrote:
Hello.
Simple code:
#include <ev.h>
#include <stdio.h>
#include <pthread.h>
static void async_cb (EV_P_ ev_async *w, int revents) {
printf("never got called :(\n");
return;
}
static ev_async async_w;
static struct ev_loop* dyn_loop;
void* thread_loop(void* args) {
dyn_loop = ev_loop_new(0);
ev_async_init(&async_w, async_cb);
ev_async_start(dyn_loop, &async_w);
ev_run(dyn_loop);
int a = 0;
}
static ev_async mysig;
static void timeout_cb(EV_P_ ev_timer *w, int revents) {
ev_async_send (dyn_loop, &mysig);
}
struct ev_loop* loop = ev_default_loop(0);
int main(int argc, char **argv) {
pthread_t thread;
pthread_create(&thread, NULL, thread_loop, NULL);
static ev_timer tw;
ev_timer_init (&tw, timeout_cb, 5, 3);
ev_timer_start(loop, &tw);
ev_run(loop, 0);
return 0;
}
Should cause async_cb triggering from timeout_cb, but this never happens
(timout_cb is triggering without problems).
Tried many combinations (like creating dyn_loop in main thread etc - no
effect). Please help!
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev