… | |
… | |
549 | Coro::on_enter { |
549 | Coro::on_enter { |
550 | # on entering the thread, we set an VTALRM handler to cede |
550 | # on entering the thread, we set an VTALRM handler to cede |
551 | $SIG{VTALRM} = sub { cede }; |
551 | $SIG{VTALRM} = sub { cede }; |
552 | # and then start the interval timer |
552 | # and then start the interval timer |
553 | Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0.01, 0.01; |
553 | Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0.01, 0.01; |
554 | }; |
554 | }; |
555 | Coro::on_leave { |
555 | Coro::on_leave { |
556 | # on leaving the thread, we stop the interval timer again |
556 | # on leaving the thread, we stop the interval timer again |
557 | Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0, 0; |
557 | Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0, 0; |
558 | }; |
558 | }; |
559 | |
559 | |
560 | &{+shift}; |
560 | &{+shift}; |
561 | } |
561 | } |
562 | |
562 | |
563 | # use like this: |
563 | # use like this: |
564 | timeslice { |
564 | timeslice { |
565 | # The following is an endless loop that would normally |
565 | # The following is an endless loop that would normally |
566 | # monopolise the process. Since it runs in a timesliced |
566 | # monopolise the process. Since it runs in a timesliced |
… | |
… | |
778 | destroyed, that is, after it's resources have been freed but before |
778 | destroyed, that is, after it's resources have been freed but before |
779 | it is joined. The callback gets passed the terminate/cancel |
779 | it is joined. The callback gets passed the terminate/cancel |
780 | arguments, if any, and *must not* die, under any circumstances. |
780 | arguments, if any, and *must not* die, under any circumstances. |
781 | |
781 | |
782 | There can be any number of "on_destroy" callbacks per coro, and |
782 | There can be any number of "on_destroy" callbacks per coro, and |
783 | there is no way currently to remove a callback once added. |
783 | there is currently no way to remove a callback once added. |
784 | |
784 | |
785 | $oldprio = $coro->prio ($newprio) |
785 | $oldprio = $coro->prio ($newprio) |
786 | Sets (or gets, if the argument is missing) the priority of the coro |
786 | Sets (or gets, if the argument is missing) the priority of the coro |
787 | thread. Higher priority coro get run before lower priority coros. |
787 | thread. Higher priority coro get run before lower priority coros. |
788 | Priorities are small signed integers (currently -4 .. +3), that you |
788 | Priorities are small signed integers (currently -4 .. +3), that you |