SCM Repository
Diff of /sml/trunk/src/cml/src/IO/new-bin-io-fn.sml
Parent Directory
|
Revision Log
|
Patch
revision 1322, Mon Apr 21 14:01:59 2003 UTC | revision 1323, Sat May 10 03:37:36 2003 UTC | |
---|---|---|
# | Line 411 | Line 411 |
411 | end | end |
412 | *) | *) |
413 | ||
414 | (* IO event constructors: | |
415 | * We exploit the "functional" nature of stream IO to implement the event | |
416 | * constructors. These constructors spawn a thread to do the operation | |
417 | * and and write the result in an iVar that serves as the synchronization | |
418 | * value. | |
419 | * NOTE: this implementation has the weakness that it prevents shutdown when | |
420 | * everything else is deadlocked, since the thread that is spawned to actually | |
421 | * do the IO could proceed. | |
422 | *) | |
423 | local | |
424 | datatype 'a result = RES of 'a | EXN of exn | |
425 | fun doInput inputOp = let | |
426 | fun input arg = RES(inputOp arg) handle ex => EXN ex | |
427 | in | |
428 | fn arg => CML.guard (fn () => let | |
429 | val resV = SV.iVar() | |
430 | in | |
431 | CML.spawn (fn () => SV.iPut(resV, input arg)); | |
432 | CML.wrap(SV.iGetEvt resV, | |
433 | fn (RES x) => x | (EXN ex) => raise ex) | |
434 | end) | |
435 | end | |
436 | in | |
437 | val input1Evt = doInput input1 | |
438 | val inputEvt = doInput input | |
439 | val inputNEvt = doInput inputN | |
440 | val inputAllEvt = doInput inputAll | |
441 | end (* local *) | |
442 | ||
443 | ||
444 | (*** Output streams ***) | (*** Output streams ***) |
445 |
|
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |