src/Pure/Concurrent/multithreading.ML
changeset 62891 7a11ea5c9626
parent 62826 eb94e570c1a4
child 62892 7485507620b6
equal deleted inserted replaced
62890:728aa05e9433 62891:7a11ea5c9626
     2     Author:     Makarius
     2     Author:     Makarius
     3 
     3 
     4 Multithreading in Poly/ML (cf. polyml/basis/Thread.sml).
     4 Multithreading in Poly/ML (cf. polyml/basis/Thread.sml).
     5 *)
     5 *)
     6 
     6 
     7 signature BASIC_MULTITHREADING =
       
     8 sig
       
     9   val interruptible: ('a -> 'b) -> 'a -> 'b
       
    10   val uninterruptible: ((('c -> 'd) -> 'c -> 'd) -> 'a -> 'b) -> 'a -> 'b
       
    11 end;
       
    12 
       
    13 signature MULTITHREADING =
     7 signature MULTITHREADING =
    14 sig
     8 sig
    15   include BASIC_MULTITHREADING
       
    16   val no_interrupts: Thread.threadAttribute list
     9   val no_interrupts: Thread.threadAttribute list
    17   val public_interrupts: Thread.threadAttribute list
    10   val public_interrupts: Thread.threadAttribute list
    18   val private_interrupts: Thread.threadAttribute list
    11   val private_interrupts: Thread.threadAttribute list
    19   val sync_interrupts: Thread.threadAttribute list -> Thread.threadAttribute list
    12   val sync_interrupts: Thread.threadAttribute list -> Thread.threadAttribute list
    20   val interrupted: unit -> unit  (*exception Interrupt*)
    13   val interrupted: unit -> unit  (*exception Interrupt*)
    21   val with_attributes: Thread.threadAttribute list -> (Thread.threadAttribute list -> 'a) -> 'a
    14   val with_attributes: Thread.threadAttribute list -> (Thread.threadAttribute list -> 'a) -> 'a
       
    15   val interruptible: ('a -> 'b) -> 'a -> 'b
       
    16   val uninterruptible: ((('c -> 'd) -> 'c -> 'd) -> 'a -> 'b) -> 'a -> 'b
    22   val max_threads_value: unit -> int
    17   val max_threads_value: unit -> int
    23   val max_threads_update: int -> unit
    18   val max_threads_update: int -> unit
    24   val enabled: unit -> bool
    19   val enabled: unit -> bool
    25   val sync_wait: Thread.threadAttribute list option -> Time.time option ->
    20   val sync_wait: Thread.threadAttribute list option -> Time.time option ->
    26     ConditionVar.conditionVar -> Mutex.mutex -> bool Exn.result
    21     ConditionVar.conditionVar -> Mutex.mutex -> bool Exn.result
    72     val orig_atts = safe_interrupts (Thread.getAttributes ());
    67     val orig_atts = safe_interrupts (Thread.getAttributes ());
    73     val result = Exn.capture (fn () =>
    68     val result = Exn.capture (fn () =>
    74       (Thread.setAttributes (safe_interrupts new_atts); e orig_atts)) ();
    69       (Thread.setAttributes (safe_interrupts new_atts); e orig_atts)) ();
    75     val _ = Thread.setAttributes orig_atts;
    70     val _ = Thread.setAttributes orig_atts;
    76   in Exn.release result end;
    71   in Exn.release result end;
    77 
       
    78 
       
    79 (* portable wrappers *)
       
    80 
    72 
    81 fun interruptible f x = with_attributes public_interrupts (fn _ => f x);
    73 fun interruptible f x = with_attributes public_interrupts (fn _ => f x);
    82 
    74 
    83 fun uninterruptible f x =
    75 fun uninterruptible f x =
    84   with_attributes no_interrupts (fn atts =>
    76   with_attributes no_interrupts (fn atts =>
   177   in res end);
   169   in res end);
   178 
   170 
   179 end;
   171 end;
   180 
   172 
   181 end;
   173 end;
   182 
       
   183 structure Basic_Multithreading: BASIC_MULTITHREADING = Multithreading;
       
   184 open Basic_Multithreading;