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

Comparing Coro/README (file contents):
Revision 1.27 by root, Fri Dec 25 07:17:12 2009 UTC vs.
Revision 1.28 by root, Sun Feb 13 04:39:15 2011 UTC

411 "terminate" or "cancel" functions. "join" can be called concurrently 411 "terminate" or "cancel" functions. "join" can be called concurrently
412 from multiple coro, and all will be resumed and given the status 412 from multiple coro, and all will be resumed and given the status
413 return once the $coro terminates. 413 return once the $coro terminates.
414 414
415 $coro->on_destroy (\&cb) 415 $coro->on_destroy (\&cb)
416 Registers a callback that is called when this coro gets destroyed, 416 Registers a callback that is called when this coro thread gets
417 but before it is joined. The callback gets passed the terminate 417 destroyed, but before it is joined. The callback gets passed the
418 arguments, if any, and *must not* die, under any circumstances. 418 terminate arguments, if any, and *must not* die, under any
419 circumstances.
420
421 There can be any number of "on_destroy" callbacks per coro.
419 422
420 $oldprio = $coro->prio ($newprio) 423 $oldprio = $coro->prio ($newprio)
421 Sets (or gets, if the argument is missing) the priority of the coro. 424 Sets (or gets, if the argument is missing) the priority of the coro
422 Higher priority coro get run before lower priority coro. Priorities 425 thread. Higher priority coro get run before lower priority coros.
423 are small signed integers (currently -4 .. +3), that you can refer 426 Priorities are small signed integers (currently -4 .. +3), that you
424 to using PRIO_xxx constants (use the import tag :prio to get then): 427 can refer to using PRIO_xxx constants (use the import tag :prio to
428 get then):
425 429
426 PRIO_MAX > PRIO_HIGH > PRIO_NORMAL > PRIO_LOW > PRIO_IDLE > PRIO_MIN 430 PRIO_MAX > PRIO_HIGH > PRIO_NORMAL > PRIO_LOW > PRIO_IDLE > PRIO_MIN
427 3 > 1 > 0 > -1 > -3 > -4 431 3 > 1 > 0 > -1 > -3 > -4
428 432
429 # set priority to HIGH 433 # set priority to HIGH
430 current->prio (PRIO_HIGH); 434 current->prio (PRIO_HIGH);
431 435
432 The idle coro ($Coro::idle) always has a lower priority than any 436 The idle coro thread ($Coro::idle) always has a lower priority than
433 existing coro. 437 any existing coro.
434 438
435 Changing the priority of the current coro will take effect 439 Changing the priority of the current coro will take effect
436 immediately, but changing the priority of coro in the ready queue 440 immediately, but changing the priority of a coro in the ready queue
437 (but not running) will only take effect after the next schedule (of 441 (but not running) will only take effect after the next schedule (of
438 that coro). This is a bug that will be fixed in some future version. 442 that coro). This is a bug that will be fixed in some future version.
439 443
440 $newprio = $coro->nice ($change) 444 $newprio = $coro->nice ($change)
441 Similar to "prio", but subtract the given value from the priority 445 Similar to "prio", but subtract the given value from the priority
442 (i.e. higher values mean lower priority, just as in unix). 446 (i.e. higher values mean lower priority, just as in UNIX's nice
447 command).
443 448
444 $olddesc = $coro->desc ($newdesc) 449 $olddesc = $coro->desc ($newdesc)
445 Sets (or gets in case the argument is missing) the description for 450 Sets (or gets in case the argument is missing) the description for
446 this coro. This is just a free-form string you can associate with a 451 this coro thread. This is just a free-form string you can associate
447 coro. 452 with a coro.
448 453
449 This method simply sets the "$coro->{desc}" member to the given 454 This method simply sets the "$coro->{desc}" member to the given
450 string. You can modify this member directly if you wish. 455 string. You can modify this member directly if you wish, and in
456 fact, this is often preferred to indicate major processing states
457 that cna then be seen for example in a Coro::Debug session:
458
459 sub my_long_function {
460 local $Coro::current->{desc} = "now in my_long_function";
461 ...
462 $Coro::current->{desc} = "my_long_function: phase 1";
463 ...
464 $Coro::current->{desc} = "my_long_function: phase 2";
465 ...
466 }
451 467
452GLOBAL FUNCTIONS 468GLOBAL FUNCTIONS
453 Coro::nready 469 Coro::nready
454 Returns the number of coro that are currently in the ready state, 470 Returns the number of coro that are currently in the ready state,
455 i.e. that can be switched to by calling "schedule" directory or 471 i.e. that can be switched to by calling "schedule" directory or
472 The reason this function exists is that many event libraries (such 488 The reason this function exists is that many event libraries (such
473 as the venerable Event module) are not thread-safe (a weaker form of 489 as the venerable Event module) are not thread-safe (a weaker form of
474 reentrancy). This means you must not block within event callbacks, 490 reentrancy). This means you must not block within event callbacks,
475 otherwise you might suffer from crashes or worse. The only event 491 otherwise you might suffer from crashes or worse. The only event
476 library currently known that is safe to use without "unblock_sub" is 492 library currently known that is safe to use without "unblock_sub" is
477 EV. 493 EV (but you might still run into deadlocks if all event loops are
494 blocked).
478 495
479 Coro will try to catch you when you block in the event loop 496 Coro will try to catch you when you block in the event loop
480 ("FATAL:$Coro::IDLE blocked itself"), but this is just best effort 497 ("FATAL:$Coro::IDLE blocked itself"), but this is just best effort
481 and only works when you do not run your own event loop. 498 and only works when you do not run your own event loop.
482 499
616 ithreads (for example, that memory or files would be shared), showing 633 ithreads (for example, that memory or files would be shared), showing
617 his lack of understanding of this area - if it is hard to understand for 634 his lack of understanding of this area - if it is hard to understand for
618 Chip, it is probably not obvious to everybody). 635 Chip, it is probably not obvious to everybody).
619 636
620 What follows is an ultra-condensed version of my talk about threads in 637 What follows is an ultra-condensed version of my talk about threads in
621 scripting languages given onthe perl workshop 2009: 638 scripting languages given on the perl workshop 2009:
622 639
623 The so-called "ithreads" were originally implemented for two reasons: 640 The so-called "ithreads" were originally implemented for two reasons:
624 first, to (badly) emulate unix processes on native win32 perls, and 641 first, to (badly) emulate unix processes on native win32 perls, and
625 secondly, to replace the older, real thread model ("5.005-threads"). 642 secondly, to replace the older, real thread model ("5.005-threads").
626 643

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines