src/Pure/ML-Systems/multithreading.ML
author wenzelm
Sun Mar 01 23:36:12 2009 +0100 (2009-03-01)
changeset 30190 479806475f3c
parent 29564 f8b933a62151
child 30612 cb6421b6a18f
permissions -rw-r--r--
use long names for old-style fold combinators;
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@28160
    24
  val with_attributes: Thread.threadAttribute list ->
wenzelm@28160
    25
    (Thread.threadAttribute list -> 'a -> 'b) -> 'a -> 'b
wenzelm@24690
    26
  val self_critical: unit -> bool
wenzelm@25704
    27
  val serial: unit -> int
wenzelm@24690
    28
end;
wenzelm@24690
    29
wenzelm@24690
    30
structure Multithreading: MULTITHREADING =
wenzelm@24690
    31
struct
wenzelm@24690
    32
wenzelm@25735
    33
(* options *)
wenzelm@25735
    34
wenzelm@24690
    35
val trace = ref (0: int);
wenzelm@24690
    36
fun tracing _ _ = ();
wenzelm@24690
    37
wenzelm@24690
    38
val available = false;
wenzelm@24690
    39
val max_threads = ref (1: int);
wenzelm@28460
    40
fun max_threads_value () = 1: int;
wenzelm@28554
    41
fun enabled () = false;
wenzelm@24690
    42
wenzelm@28187
    43
val no_interrupts =
wenzelm@28187
    44
  [Thread.EnableBroadcastInterrupt false, Thread.InterruptState Thread.InterruptDefer];
wenzelm@28187
    45
wenzelm@28187
    46
val regular_interrupts =
wenzelm@28187
    47
  [Thread.EnableBroadcastInterrupt true, Thread.InterruptState Thread.InterruptAsynchOnce];
wenzelm@28160
    48
wenzelm@28160
    49
fun with_attributes _ f x = f [] x;
wenzelm@28149
    50
wenzelm@25735
    51
wenzelm@25735
    52
(* critical section *)
wenzelm@25735
    53
wenzelm@24690
    54
fun self_critical () = false;
wenzelm@24690
    55
fun NAMED_CRITICAL _ e = e ();
wenzelm@24690
    56
fun CRITICAL e = e ();
wenzelm@24690
    57
wenzelm@25735
    58
wenzelm@25735
    59
(* serial numbers *)
wenzelm@25735
    60
wenzelm@25704
    61
local val count = ref (0: int)
wenzelm@25704
    62
in fun serial () = (count := ! count + 1; ! count) end;
wenzelm@25704
    63
wenzelm@28123
    64
end;
wenzelm@28123
    65
wenzelm@28123
    66
structure BasicMultithreading: BASIC_MULTITHREADING = Multithreading;
wenzelm@28123
    67
open BasicMultithreading;