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

Comparing Coro/Coro.pm (file contents):
Revision 1.324 by root, Tue Mar 4 12:32:02 2014 UTC vs.
Revision 1.325 by root, Thu Mar 6 06:40:31 2014 UTC

793the thread is inside a C callback that doesn't expect to be canceled, 793the thread is inside a C callback that doesn't expect to be canceled,
794bad things can happen, or if the cancelled thread insists on running 794bad things can happen, or if the cancelled thread insists on running
795complicated cleanup handlers that rely on its thread context, things will 795complicated cleanup handlers that rely on its thread context, things will
796not work. 796not work.
797 797
798Any cleanup code being run (e.g. from C<guard> blocks) will be run without 798Any cleanup code being run (e.g. from C<guard> blocks, destructors and so
799a thread context, and is not allowed to switch to other threads. On the 799on) will be run without a thread context, and is not allowed to switch
800to other threads. A common mistake is to call C<< ->cancel >> from a
801destructor called by die'ing inside the thread to be cancelled for
802example.
803
800plus side, C<< ->cancel >> will always clean up the thread, no matter 804On the plus side, C<< ->cancel >> will always clean up the thread, no
801what. If your cleanup code is complex or you want to avoid cancelling a 805matter what. If your cleanup code is complex or you want to avoid
802C-thread that doesn't know how to clean up itself, it can be better to C<< 806cancelling a C-thread that doesn't know how to clean up itself, it can be
803->throw >> an exception, or use C<< ->safe_cancel >>. 807better to C<< ->throw >> an exception, or use C<< ->safe_cancel >>.
804 808
805The arguments to C<< ->cancel >> are not copied, but instead will 809The arguments to C<< ->cancel >> are not copied, but instead will
806be referenced directly (e.g. if you pass C<$var> and after the call 810be referenced directly (e.g. if you pass C<$var> and after the call
807change that variable, then you might change the return values passed to 811change that variable, then you might change the return values passed to
808e.g. C<join>, so don't do that). 812e.g. C<join>, so don't do that).
814 818
815=item $coro->safe_cancel ($arg...) 819=item $coro->safe_cancel ($arg...)
816 820
817Works mostly like C<< ->cancel >>, but is inherently "safer", and 821Works mostly like C<< ->cancel >>, but is inherently "safer", and
818consequently, can fail with an exception in cases the thread is not in a 822consequently, can fail with an exception in cases the thread is not in a
819cancellable state. 823cancellable state. Essentially, C<< ->safe_cancel >> is a C<< ->cancel >>
824with extra checks before canceling.
820 825
821This method works a bit like throwing an exception that cannot be caught 826It works a bit like throwing an exception that cannot be caught -
822- specifically, it will clean up the thread from within itself, so 827specifically, it will clean up the thread from within itself, so all
823all cleanup handlers (e.g. C<guard> blocks) are run with full thread 828cleanup handlers (e.g. C<guard> blocks) are run with full thread
824context and can block if they wish. The downside is that there is no 829context and can block if they wish. The downside is that there is no
825guarantee that the thread can be cancelled when you call this method, and 830guarantee that the thread can be cancelled when you call this method, and
826therefore, it might fail. It is also considerably slower than C<cancel> or 831therefore, it might fail. It is also considerably slower than C<cancel> or
827C<terminate>. 832C<terminate>.
828 833

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines