@@ -93,25 +93,27 @@ fn listen<T: send, U>(f: fn(chan<T>) -> U) -> U {
93
93
f ( po. chan ( ) )
94
94
}
95
95
96
- resource port_ptr<T : send>( po: * rust_port) {
97
- // Once the port is detached it's guaranteed not to receive further
98
- // messages
99
- let yield = 0 u;
100
- let yieldp = ptr:: addr_of ( yield ) ;
101
- rustrt:: rust_port_begin_detach ( po, yieldp) ;
102
- if yield != 0 u {
103
- // Need to wait for the port to be detached
104
- // FIXME: If this fails then we're going to leave our port
105
- // in a bogus state. (Issue #1988)
106
- task:: yield ( ) ;
107
- }
108
- rustrt:: rust_port_end_detach ( po) ;
96
+ resource port_ptr<T : send>( po: * rust_port) unsafe {
97
+ task:: unkillable { ||
98
+ // Once the port is detached it's guaranteed not to receive further
99
+ // messages
100
+ let yield = 0 u;
101
+ let yieldp = ptr:: addr_of ( yield ) ;
102
+ rustrt:: rust_port_begin_detach ( po, yieldp) ;
103
+ if yield != 0 u {
104
+ // Need to wait for the port to be detached
105
+ // FIXME: If this fails then we're going to leave our port
106
+ // in a bogus state. (Issue #1988)
107
+ task:: yield ( ) ;
108
+ }
109
+ rustrt:: rust_port_end_detach ( po) ;
109
110
110
- // Drain the port so that all the still-enqueued items get dropped
111
- while rustrt:: rust_port_size ( po) > 0 u {
112
- recv_ :: < T > ( po) ;
111
+ // Drain the port so that all the still-enqueued items get dropped
112
+ while rustrt:: rust_port_size ( po) > 0 u {
113
+ recv_ :: < T > ( po) ;
114
+ }
115
+ rustrt:: del_port ( po) ;
113
116
}
114
- rustrt:: del_port ( po) ;
115
117
}
116
118
117
119
#[ doc = "
@@ -458,4 +460,25 @@ fn test_listen() {
458
460
}
459
461
assert parent. recv ( ) == "oatmeal-salad" ;
460
462
}
463
+ }
464
+
465
+ #[ test]
466
+ #[ ignore( cfg( target_os="win32" ) ) ]
467
+ fn test_port_detach_fail ( ) {
468
+ iter:: repeat ( 100 u) { ||
469
+ let builder = task:: builder ( ) ;
470
+ task:: unsupervise ( builder) ;
471
+ task:: run ( builder) { ||
472
+ let po = port ( ) ;
473
+ let ch = po. chan ( ) ;
474
+
475
+ task:: spawn { ||
476
+ fail;
477
+ }
478
+
479
+ task:: spawn { ||
480
+ ch. send ( ( ) ) ;
481
+ }
482
+ }
483
+ }
461
484
}
0 commit comments