… | |
… | |
16 | cede; # yield to coro |
16 | cede; # yield to coro |
17 | print "3\n"; |
17 | print "3\n"; |
18 | cede; # and again |
18 | cede; # and again |
19 | |
19 | |
20 | # use locking |
20 | # use locking |
21 | use Coro::Semaphore; |
|
|
22 | my $lock = new Coro::Semaphore; |
21 | my $lock = new Coro::Semaphore; |
23 | my $locked; |
22 | my $locked; |
24 | |
23 | |
25 | $lock->down; |
24 | $lock->down; |
26 | $locked = 1; |
25 | $locked = 1; |
… | |
… | |
767 | current Coro. |
766 | current Coro. |
768 | |
767 | |
769 | This is a rather brutal way to free a coro, with some limitations - if |
768 | This is a rather brutal way to free a coro, with some limitations - if |
770 | the thread is inside a C callback that doesn't expect to be canceled, |
769 | the thread is inside a C callback that doesn't expect to be canceled, |
771 | bad things can happen, or if the cancelled thread insists on running |
770 | bad things can happen, or if the cancelled thread insists on running |
772 | complicated cleanup handlers that rely on it'S thread context, things will |
771 | complicated cleanup handlers that rely on its thread context, things will |
773 | not work. |
772 | not work. |
774 | |
773 | |
775 | Any cleanup code being run (e.g. from C<guard> blocks) will be run without |
774 | Any cleanup code being run (e.g. from C<guard> blocks) will be run without |
776 | a thread context, and is not allowed to switch to other threads. On the |
775 | a thread context, and is not allowed to switch to other threads. On the |
777 | plus side, C<< ->cancel >> will always clean up the thread, no matter |
776 | plus side, C<< ->cancel >> will always clean up the thread, no matter |