@@ -525,7 +525,8 @@ mod procsrv {
525
525
export run;
526
526
export close;
527
527
528
- type handle = chan[ request] ;
528
+ type handle = rec( option : : t[ task] task,
529
+ chan[ request] chan) ;
529
530
530
531
tag request {
531
532
exec( str , str, vec[ str] , chan[ response] ) ;
@@ -535,22 +536,28 @@ mod procsrv {
535
536
type response = rec( int pid, int outfd) ;
536
537
537
538
fn mk( ) -> handle {
538
- task : : worker( worker) . chan
539
+ auto res = task : : worker( worker) ;
540
+ ret rec( task = option:: some( res. task) ,
541
+ chan = res. chan) ;
539
542
}
540
543
541
544
fn clone( & handle handle) -> handle {
542
- task : : clone_chan( handle)
545
+ // Sharing tasks across tasks appears to be (yet another) recipe for
546
+ // disaster, so our handle clones will not get the task pointer.
547
+ rec( task = option : : none,
548
+ chan = task : : clone_chan( handle. chan) )
543
549
}
544
550
545
551
fn close( & handle handle) {
546
- task:: send( handle, stop) ;
552
+ task:: send( handle. chan, stop) ;
553
+ task:: join( option:: get( handle. task) ) ;
547
554
}
548
555
549
556
fn run( & handle handle, & str lib_path,
550
557
& str prog, & vec[ str] args) -> rec( int status, str out) {
551
558
auto p = port[ response] ( ) ;
552
559
auto ch = chan( p) ;
553
- task:: send( handle,
560
+ task:: send( handle. chan ,
554
561
exec( lib_path, prog, args, ch) ) ;
555
562
556
563
auto resp = task:: recv( p) ;
0 commit comments