質問

How to view the output of following code?

fun daughter () = let
            val daughter_tid = getTid();
          in
            print ("DAUGHTER : my tid = " ^ (tidToString daughter_tid) ^ "\n")
          end;
fun mother () =
        let
            val mother_tid = getTid();
            val daughter_tid = spawn daughter;
        in
            print("MOTHER : my Tid = " ^ (tidToString mother_tid) ^ "Daughter's tid = " ^ (tidToString daughter_tid) ^ "\n")
        end;

        RunCML.doit(mother, SOME(Time.fromMilliseconds 10));

The code compiles fine and suppose to provide output as follows :

DAUGHTER : my tid = [0004]
MOTHER : my tid [0003] DAUGHETR's Tid = [0004]
役に立ちましたか?

解決

You must use TextIO.print instead of print to get the right output. Without such an explicit reference, the CML version of TextIO does not get loaded when your program is compiled and the print function resolves to the SML/NJ version; since this version of print is not thread safe, problems will result. You can see CML FAQ for more details.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top