… | |
… | |
214 | C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for |
214 | C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for |
215 | recommended ones. |
215 | recommended ones. |
216 | |
216 | |
217 | See the description of C<ev_embed> watchers for more info. |
217 | See the description of C<ev_embed> watchers for more info. |
218 | |
218 | |
219 | =item ev_set_allocator (void *(*cb)(void *ptr, long size)) |
219 | =item ev_set_allocator (void *(*cb)(void *ptr, long size)) [NOT REENTRANT] |
220 | |
220 | |
221 | Sets the allocation function to use (the prototype is similar - the |
221 | Sets the allocation function to use (the prototype is similar - the |
222 | semantics are identical to the C<realloc> C89/SuS/POSIX function). It is |
222 | semantics are identical to the C<realloc> C89/SuS/POSIX function). It is |
223 | used to allocate and free memory (no surprises here). If it returns zero |
223 | used to allocate and free memory (no surprises here). If it returns zero |
224 | when memory needs to be allocated (C<size != 0>), the library might abort |
224 | when memory needs to be allocated (C<size != 0>), the library might abort |
… | |
… | |
250 | } |
250 | } |
251 | |
251 | |
252 | ... |
252 | ... |
253 | ev_set_allocator (persistent_realloc); |
253 | ev_set_allocator (persistent_realloc); |
254 | |
254 | |
255 | =item ev_set_syserr_cb (void (*cb)(const char *msg)); |
255 | =item ev_set_syserr_cb (void (*cb)(const char *msg)); [NOT REENTRANT] |
256 | |
256 | |
257 | Set the callback function to call on a retryable system call error (such |
257 | Set the callback function to call on a retryable system call error (such |
258 | as failed select, poll, epoll_wait). The message is a printable string |
258 | as failed select, poll, epoll_wait). The message is a printable string |
259 | indicating the system call or subsystem causing the problem. If this |
259 | indicating the system call or subsystem causing the problem. If this |
260 | callback is set, then libev will expect it to remedy the situation, no |
260 | callback is set, then libev will expect it to remedy the situation, no |
… | |
… | |
3303 | |
3303 | |
3304 | =head1 THREADS AND COROUTINES |
3304 | =head1 THREADS AND COROUTINES |
3305 | |
3305 | |
3306 | =head2 THREADS |
3306 | =head2 THREADS |
3307 | |
3307 | |
3308 | Libev itself is thread-safe (unless the opposite is specifically |
3308 | All libev functions are reentrant and thread-safe unless explicitly |
3309 | documented for a function), but it uses no locking itself. This means that |
3309 | documented otherwise, but it uses no locking itself. This means that you |
3310 | you can use as many loops as you want in parallel, as long as only one |
3310 | can use as many loops as you want in parallel, as long as there are no |
3311 | thread ever calls into one libev function with the same loop parameter: |
3311 | concurrent calls into any libev function with the same loop parameter |
|
|
3312 | (C<ev_default_*> calls have an implicit default loop parameter, of |
3312 | libev guarantees that different event loops share no data structures that |
3313 | course): libev guarantees that different event loops share no data |
3313 | need locking. |
3314 | structures that need any locking. |
3314 | |
3315 | |
3315 | Or to put it differently: calls with different loop parameters can be done |
3316 | Or to put it differently: calls with different loop parameters can be done |
3316 | concurrently from multiple threads, calls with the same loop parameter |
3317 | concurrently from multiple threads, calls with the same loop parameter |
3317 | must be done serially (but can be done from different threads, as long as |
3318 | must be done serially (but can be done from different threads, as long as |
3318 | only one thread ever is inside a call at any point in time, e.g. by using |
3319 | only one thread ever is inside a call at any point in time, e.g. by using |
3319 | a mutex per loop). |
3320 | a mutex per loop). |
3320 | |
3321 | |
3321 | Specifically to support threads (and signal handlers), libev implements |
3322 | Specifically to support threads (and signal handlers), libev implements |
3322 | so-called C<ev_async> watchers, which allow some limited form of |
3323 | so-called C<ev_async> watchers, which allow some limited form of |
3323 | concurrency on the same event loop. |
3324 | concurrency on the same event loop, namely waking it up "from the |
|
|
3325 | outside". |
3324 | |
3326 | |
3325 | If you want to know which design (one loop, locking, or multiple loops |
3327 | If you want to know which design (one loop, locking, or multiple loops |
3326 | without or something else still) is best for your problem, then I cannot |
3328 | without or something else still) is best for your problem, then I cannot |
3327 | help you. I can give some generic advice however: |
3329 | help you, but here is some generic advice: |
3328 | |
3330 | |
3329 | =over 4 |
3331 | =over 4 |
3330 | |
3332 | |
3331 | =item * most applications have a main thread: use the default libev loop |
3333 | =item * most applications have a main thread: use the default libev loop |
3332 | in that thread, or create a separate thread running only the default loop. |
3334 | in that thread, or create a separate thread running only the default loop. |