src/Pure/ML-Systems/multithreading.ML
author wenzelm
Fri Mar 20 20:20:09 2009 +0100 (2009-03-20 ago)
changeset 30612 cb6421b6a18f
parent 29564 f8b933a62151
child 32184 cfa0ef0c0c5f
permissions -rw-r--r--
future_job: do not inherit attributes, but enforce restricted interrupts -- attempt to prevent interrupt race conditions;
wenzelm@24690
     1
(*  Title:      Pure/ML-Systems/multithreading.ML
wenzelm@24690
     2
    Author:     Makarius
wenzelm@24690
     3
wenzelm@28149
     4
Dummy implementation of multithreading setup.
wenzelm@24690
     5
*)
wenzelm@24690
     6
wenzelm@25704
     7
signature BASIC_MULTITHREADING =
wenzelm@25704
     8
sig
wenzelm@25704
     9
  val NAMED_CRITICAL: string -> (unit -> 'a) -> 'a
wenzelm@25704
    10
  val CRITICAL: (unit -> 'a) -> 'a
wenzelm@25704
    11
end;
wenzelm@25704
    12
wenzelm@24690
    13
signature MULTITHREADING =
wenzelm@24690
    14
sig
wenzelm@25704
    15
  include BASIC_MULTITHREADING
wenzelm@24690
    16
  val trace: int ref
wenzelm@24690
    17
  val tracing: int -> (unit -> string) -> unit
wenzelm@24690
    18
  val available: bool
wenzelm@24690
    19
  val max_threads: int ref
wenzelm@25775
    20
  val max_threads_value: unit -> int
wenzelm@28554
    21
  val enabled: unit -> bool
wenzelm@28149
    22
  val no_interrupts: Thread.threadAttribute list
wenzelm@28160
    23
  val regular_interrupts: Thread.threadAttribute list
wenzelm@30612
    24
  val restricted_interrupts: Thread.threadAttribute list
wenzelm@28160
    25
  val with_attributes: Thread.threadAttribute list ->
wenzelm@28160
    26
    (Thread.threadAttribute list -> 'a -> 'b) -> 'a -> 'b
wenzelm@24690
    27
  val self_critical: unit -> bool
wenzelm@25704
    28
  val serial: unit -> int
wenzelm@24690
    29
end;
wenzelm@24690
    30
wenzelm@24690
    31
structure Multithreading: MULTITHREADING =
wenzelm@24690
    32
struct
wenzelm@24690
    33
wenzelm@25735
    34
(* options *)
wenzelm@25735
    35
wenzelm@24690
    36
val trace = ref (0: int);
wenzelm@24690
    37
fun tracing _ _ = ();
wenzelm@24690
    38
wenzelm@24690
    39
val available = false;
wenzelm@24690
    40
val max_threads = ref (1: int);
wenzelm@28460
    41
fun max_threads_value () = 1: int;
wenzelm@28554
    42
fun enabled () = false;
wenzelm@24690
    43
wenzelm@28187
    44
val no_interrupts =
wenzelm@28187
    45
  [Thread.EnableBroadcastInterrupt false, Thread.InterruptState Thread.InterruptDefer];
wenzelm@28187
    46
wenzelm@28187
    47
val regular_interrupts =
wenzelm@28187
    48
  [Thread.EnableBroadcastInterrupt true, Thread.InterruptState Thread.InterruptAsynchOnce];
wenzelm@28160
    49
wenzelm@30612
    50
val restricted_interrupts =
wenzelm@30612
    51
  [Thread.EnableBroadcastInterrupt false, Thread.InterruptState Thread.InterruptAsynchOnce];
wenzelm@30612
    52
wenzelm@28160
    53
fun with_attributes _ f x = f [] x;
wenzelm@28149
    54
wenzelm@25735
    55
wenzelm@25735
    56
(* critical section *)
wenzelm@25735
    57
wenzelm@24690
    58
fun self_critical () = false;
wenzelm@24690
    59
fun NAMED_CRITICAL _ e = e ();
wenzelm@24690
    60
fun CRITICAL e = e ();
wenzelm@24690
    61
wenzelm@25735
    62
wenzelm@25735
    63
(* serial numbers *)
wenzelm@25735
    64
wenzelm@25704
    65
local val count = ref (0: int)
wenzelm@25704
    66
in fun serial () = (count := ! count + 1; ! count) end;
wenzelm@25704
    67
wenzelm@28123
    68
end;
wenzelm@28123
    69
wenzelm@28123
    70
structure BasicMultithreading: BASIC_MULTITHREADING = Multithreading;
wenzelm@28123
    71
open BasicMultithreading;