libev out of context thread

Varun Chandramohan cvaruneng04 at gmail.com
Wed Dec 11 03:11:02 CET 2013


Hi All,

I have a basic question using libev. Before asking the question let me put
in context of what iam trying to do.

Thread 1 -> Puts my_struct ptr in an array (protected by lock)
Thread 2 -> on lock released reads the entry from array. As expected
thread2 {
 while (1)
 {
    check lock
    read from array
     release lock
}

The need to use libev comes at this point. After I read something from
array I would want to add the new sd to the loop. However I get the socket
descriptor only after I read from the array. So I will have to run
ev_loop() prior to adding any descriptors. In order to solve this problem I
plan to just create another thread before the while(1) loop.
in thread all I would do is

void* WPEVThread(void *ctx)

{

#pragma unused(ctx)

    ev_loop(loop, 0);

    return NULL;

}

Once I have a sd to add to loop can I call

    ev_io_init(&d_packet->io, connect_ps_cb, d_packet->connect_sd, EV_WRITE|
EV_READ);

    ev_timer_init(&d_packet->timeout_watcher, connect_timeout_handler,
DEFAULT_CONNECT_TIMER, 0);

    ev_timer_start(loop, &d_packet->timeout_watcher);

    ev_io_start(loop, &d_packet->io);

Is there a problem with this approach?

Regards,

Varun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20131211/c654b716/attachment.html>


More information about the libev mailing list