ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.179 by root, Sat Sep 13 19:14:21 2008 UTC vs.
Revision 1.180 by root, Fri Sep 19 03:45:55 2008 UTC

3240 3240
3241=head1 THREADS AND COROUTINES 3241=head1 THREADS AND COROUTINES
3242 3242
3243=head2 THREADS 3243=head2 THREADS
3244 3244
3245Libev itself is completely thread-safe, but it uses no locking. This 3245Libev itself is thread-safe (unless the opposite is specifically
3246documented for a function), but it uses no locking itself. This means that
3246means that you can use as many loops as you want in parallel, as long as 3247you can use as many loops as you want in parallel, as long as only one
3247only one thread ever calls into one libev function with the same loop 3248thread ever calls into one libev function with the same loop parameter:
3248parameter. 3249libev guarentees that different event loops share no data structures that
3250need locking.
3249 3251
3250Or put differently: calls with different loop parameters can be done in 3252Or to put it differently: calls with different loop parameters can be done
3251parallel from multiple threads, calls with the same loop parameter must be 3253concurrently from multiple threads, calls with the same loop parameter
3252done serially (but can be done from different threads, as long as only one 3254must be done serially (but can be done from different threads, as long as
3253thread ever is inside a call at any point in time, e.g. by using a mutex 3255only one thread ever is inside a call at any point in time, e.g. by using
3254per loop). 3256a mutex per loop).
3257
3258Specifically to support threads (and signal handlers), libev implements
3259so-called C<ev_async> watchers, which allow some limited form of
3260concurrency on the same event loop.
3255 3261
3256If you want to know which design (one loop, locking, or multiple loops 3262If you want to know which design (one loop, locking, or multiple loops
3257without or something else still) is best for your problem, then I cannot 3263without or something else still) is best for your problem, then I cannot
3258help you. I can give some generic advice however: 3264help you. I can give some generic advice however:
3259 3265
3277better than you currently do :-) 3283better than you currently do :-)
3278 3284
3279=item * often you need to talk to some other thread which blocks in the 3285=item * often you need to talk to some other thread which blocks in the
3280event loop - C<ev_async> watchers can be used to wake them up from other 3286event loop - C<ev_async> watchers can be used to wake them up from other
3281threads safely (or from signal contexts...). 3287threads safely (or from signal contexts...).
3288
3289=item * some watcher types are only supported in the default loop - use
3290C<ev_async> watchers to tell your other loops about any such events.
3282 3291
3283=back 3292=back
3284 3293
3285=head2 COROUTINES 3294=head2 COROUTINES
3286 3295

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines