src/Pure/Concurrent/simple_thread.ML
changeset 32051 82a9875b8707
parent 29564 f8b933a62151
child 32184 cfa0ef0c0c5f
equal deleted inserted replaced
32050:ebb9274e34b7 32051:82a9875b8707
    23 
    23 
    24 (* basic synchronization *)
    24 (* basic synchronization *)
    25 
    25 
    26 fun synchronized name lock e = Exn.release (uninterruptible (fn restore_attributes => fn () =>
    26 fun synchronized name lock e = Exn.release (uninterruptible (fn restore_attributes => fn () =>
    27   let
    27   let
    28     val _ =
    28     val immediate =
    29       if Mutex.trylock lock then ()
    29       if Mutex.trylock lock then true
    30       else
    30       else
    31        (Multithreading.tracing 3 (fn () => name ^ ": locking ...");
    31        (Multithreading.tracing 3 (fn () => name ^ ": locking ...");
    32         Mutex.lock lock;
    32         Mutex.lock lock;
    33         Multithreading.tracing 3 (fn () => name ^ ": ... locked"));
    33         Multithreading.tracing 3 (fn () => name ^ ": locked");
       
    34         false);
    34     val result = Exn.capture (restore_attributes e) ();
    35     val result = Exn.capture (restore_attributes e) ();
       
    36     val _ =
       
    37       if immediate then () else Multithreading.tracing 3 (fn () => name ^ ": unlocking ...");
    35     val _ = Mutex.unlock lock;
    38     val _ = Mutex.unlock lock;
    36   in result end) ());
    39   in result end) ());
    37 
    40 
    38 end;
    41 end;