src/Pure/ML-Systems/multithreading.ML
author wenzelm
Fri Apr 12 14:54:14 2013 +0200 (2013-04-12)
changeset 51700 c8f2bad67dbb
parent 43761 e72ba84ae58f
child 54717 42c209a6c225
permissions -rw-r--r--
tuned signature;
tuned comments;
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 available: bool
wenzelm@39616
    17
  val max_threads: int ref
wenzelm@25775
    18
  val max_threads_value: unit -> int
wenzelm@28554
    19
  val enabled: unit -> bool
wenzelm@28149
    20
  val no_interrupts: Thread.threadAttribute list
wenzelm@32295
    21
  val public_interrupts: Thread.threadAttribute list
wenzelm@32295
    22
  val private_interrupts: Thread.threadAttribute list
wenzelm@32295
    23
  val sync_interrupts: Thread.threadAttribute list -> Thread.threadAttribute list
wenzelm@41713
    24
  val interrupted: unit -> unit  (*exception Interrupt*)
wenzelm@32295
    25
  val with_attributes: Thread.threadAttribute list -> (Thread.threadAttribute list -> 'a) -> 'a
wenzelm@32295
    26
  val sync_wait: Thread.threadAttribute list option -> Time.time option ->
wenzelm@32295
    27
    ConditionVar.conditionVar -> Mutex.mutex -> bool Exn.result
wenzelm@39616
    28
  val trace: int ref
wenzelm@32295
    29
  val tracing: int -> (unit -> string) -> unit
wenzelm@32295
    30
  val tracing_time: bool -> Time.time -> (unit -> string) -> unit
wenzelm@32295
    31
  val real_time: ('a -> unit) -> 'a -> Time.time
wenzelm@24690
    32
  val self_critical: unit -> bool
wenzelm@25704
    33
  val serial: unit -> int
wenzelm@24690
    34
end;
wenzelm@24690
    35
wenzelm@24690
    36
structure Multithreading: MULTITHREADING =
wenzelm@24690
    37
struct
wenzelm@24690
    38
wenzelm@32185
    39
(* options *)
wenzelm@24690
    40
wenzelm@24690
    41
val available = false;
wenzelm@39616
    42
val max_threads = ref (1: int);
wenzelm@28460
    43
fun max_threads_value () = 1: int;
wenzelm@28554
    44
fun enabled () = false;
wenzelm@24690
    45
wenzelm@32286
    46
wenzelm@32286
    47
(* attributes *)
wenzelm@32286
    48
wenzelm@32295
    49
val no_interrupts = [];
wenzelm@32295
    50
val public_interrupts = [];
wenzelm@32295
    51
val private_interrupts = [];
wenzelm@32295
    52
fun sync_interrupts _ = [];
wenzelm@28187
    53
wenzelm@41713
    54
fun interrupted () = ();
wenzelm@41713
    55
wenzelm@32295
    56
fun with_attributes _ e = e [];
wenzelm@28160
    57
wenzelm@43761
    58
fun sync_wait _ _ _ _ = Exn.Res true;
wenzelm@32295
    59
wenzelm@32295
    60
wenzelm@32295
    61
(* tracing *)
wenzelm@30612
    62
wenzelm@39616
    63
val trace = ref (0: int);
wenzelm@32295
    64
fun tracing _ _ = ();
wenzelm@32295
    65
fun tracing_time _ _ _ = ();
wenzelm@32295
    66
fun real_time f x = (f x; Time.zeroTime);
wenzelm@32286
    67
wenzelm@25735
    68
wenzelm@25735
    69
(* critical section *)
wenzelm@25735
    70
wenzelm@24690
    71
fun self_critical () = false;
wenzelm@24690
    72
fun NAMED_CRITICAL _ e = e ();
wenzelm@24690
    73
fun CRITICAL e = e ();
wenzelm@24690
    74
wenzelm@25735
    75
wenzelm@25735
    76
(* serial numbers *)
wenzelm@25735
    77
wenzelm@39616
    78
local val count = ref (0: int)
wenzelm@25704
    79
in fun serial () = (count := ! count + 1; ! count) end;
wenzelm@25704
    80
wenzelm@28123
    81
end;
wenzelm@28123
    82
wenzelm@32286
    83
structure Basic_Multithreading: BASIC_MULTITHREADING = Multithreading;
wenzelm@32286
    84
open Basic_Multithreading;