Changeset 20069 for docs/Perl6/Spec
- Timestamp:
- 03/06/08 00:01:18 (9 months ago)
- Files:
-
- 1 modified
-
docs/Perl6/Spec/Concurrency.pod (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/Perl6/Spec/Concurrency.pod
r20063 r20069 247 247 =head2 Examples 248 248 249 =over 250 251 =item Coro as function used in a builtin 252 249 253 coro dbl { yield $_ * 2; yield $_; }; 250 254 (1..4).map:{ dbl($_) } 251 255 # should result in 2 2 6 4 252 256 253 257 =item Constant coro 258 259 coro foo { yield 42 }; 260 # always return 42 261 262 =item Yield and return 263 264 coro foo ($x) { 265 yield $x; 266 # this point with $x bound to 10 267 yield $x+1; 268 return 5; 269 ... # this is never reached, I think we all agree 270 } 271 272 =back 254 273 255 274 =head1 Threads … … 257 276 =head2 Thread methods and attributes 258 277 259 We intentionally do not list cross-machine parallelism Conc:: classes here. 260 Consult your local 6PAN mirror with a time machine. 261 262 use Conc::Processes; # fork() or createProcess based implementation 263 use Conc::Threads; # maybe it just exports &async to override the default one, yay264 use Conc::Multiplex; # this is default 278 =over 279 280 =item Create 281 282 A thread will be created using the keyword C<async> followed by 283 a codeblock being executed in this thread. 265 284 266 285 my $thr = async { … … 269 288 }; 270 289 271 Conc::Thread.this 272 Conc::Proc.this 273 290 =item Self reflection 291 292 async { 293 say "my tid is ", +self(); 294 }; 295 296 =item TODO 274 297 275 298 - numify to TIDs (as in pugs) … … 319 342 async { $f.b } 320 343 344 =back 321 345 322 346 =head2 Thread status … … 484 508 p2(); p2(); 485 509 486 coro foo { yield 42 };487 488 510 coro foo ($x) { 489 511 yield $x; … … 502 524 foo(4); # and that's all she wrote 503 525 504 coro foo ($x) {505 yield $x;506 # this point with $x bound to 10507 yield $x+1;508 return 5;509 ... # this is never reached, I think we all agree510 }511 512 526 # If you don't want your variables to get rebound, use "is copy": 513 527 coro foo ($x is copy) {...}
