ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.307 by root, Sun Dec 20 22:49:52 2009 UTC vs.
Revision 1.308 by root, Fri Dec 25 07:39:41 2009 UTC

2534 2534
2535 2535
2536=head1 FORK 2536=head1 FORK
2537 2537
2538Most event libraries are not fork-safe. The ones who are usually are 2538Most event libraries are not fork-safe. The ones who are usually are
2539because they rely on inefficient but fork-safe C<select> or C<poll> 2539because they rely on inefficient but fork-safe C<select> or C<poll> calls
2540calls. Only L<EV> is fully fork-aware. 2540- higher performance APIs such as BSD's kqueue or the dreaded Linux epoll
2541are usually badly thought-out hacks that are incompatible with fork in
2542one way or another. Only L<EV> is fully fork-aware and ensures that you
2543continue event-processing in both parent and child (or both, if you know
2544what you are doing).
2541 2545
2542This means that, in general, you cannot fork and do event processing 2546This means that, in general, you cannot fork and do event processing in
2543in the child if a watcher was created before the fork (which in turn 2547the child if the event library was initialised before the fork (which
2544initialises the event library). 2548usually happens when the first AnyEvent watcher is created, or the library
2549is loaded).
2545 2550
2546If you have to fork, you must either do so I<before> creating your first 2551If you have to fork, you must either do so I<before> creating your first
2547watcher OR you must not use AnyEvent at all in the child OR you must do 2552watcher OR you must not use AnyEvent at all in the child OR you must do
2548something completely out of the scope of AnyEvent. 2553something completely out of the scope of AnyEvent.
2549 2554
2550The problem of doing event processing in the parent I<and> the child 2555The problem of doing event processing in the parent I<and> the child
2551is much more complicated: even for backends that I<are> fork-aware or 2556is much more complicated: even for backends that I<are> fork-aware or
2552fork-safe, their behaviour is not usually what you want: fork clones all 2557fork-safe, their behaviour is not usually what you want: fork clones all
2553watchers, that means all timers, I/O watchers etc. are active in both 2558watchers, that means all timers, I/O watchers etc. are active in both
2554parent and child, which is almost never what you want. 2559parent and child, which is almost never what you want. USing C<exec>
2560to start worker children from some kind of manage rprocess is usually
2561preferred, because it is much easier and cleaner, at the expense of having
2562to have another binary.
2555 2563
2556 2564
2557=head1 SECURITY CONSIDERATIONS 2565=head1 SECURITY CONSIDERATIONS
2558 2566
2559AnyEvent can be forced to load any event model via 2567AnyEvent can be forced to load any event model via

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines