File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -314,6 +314,42 @@ mod fifo {
314
314
}
315
315
}
316
316
317
+ // https://github.com/golang/go/blob/master/test/chan/goroutines.go
318
+ mod goroutines {
319
+ use super :: * ;
320
+
321
+ fn f ( left : Chan < i32 > , right : Chan < i32 > ) {
322
+ left. send ( right. recv ( ) . unwrap ( ) ) ;
323
+ }
324
+
325
+ #[ test]
326
+ fn main ( ) {
327
+ let mut n = 10_000i32 ;
328
+ if :: std:: env:: args ( ) . count ( ) > 1 {
329
+ n = match i32:: from_str_radix ( :: std:: env:: args ( ) . nth ( 1 ) . unwrap ( ) . as_ref ( ) , 10 ) {
330
+ Ok ( n) => n,
331
+ Err ( _) => {
332
+ println ! ( "bad arg" ) ;
333
+ :: std:: process:: exit ( 1 ) ;
334
+ }
335
+ } ;
336
+ }
337
+
338
+ let leftmost = make :: < i32 > ( 0 ) ;
339
+ let mut right = leftmost. clone ( ) ;
340
+ let mut left = leftmost. clone ( ) ;
341
+
342
+ for _ in 0 ..n {
343
+ right = make :: < i32 > ( 0 ) ;
344
+ go ! ( left, right, f( left, right) ) ;
345
+ left = right. clone ( ) ;
346
+ }
347
+
348
+ go ! ( right, right. send( 1 ) ) ;
349
+ leftmost. recv ( ) . unwrap ( ) ;
350
+ }
351
+ }
352
+
317
353
// https://github.com/golang/go/blob/master/test/chan/nonblock.go
318
354
mod nonblock {
319
355
use super :: * ;
You can’t perform that action at this time.
0 commit comments