src/Pure/ML-Systems/multithreading.ML
author wenzelm
Thu Oct 01 23:27:05 2009 +0200 (2009-10-01)
changeset 32843 c8f5a7c8353f
parent 32777 8ae3a48c69d9
child 39616 8052101883c3
permissions -rw-r--r--
moved cache_conv to src/Pure/conv.ML, use Thm.cterm_cache;
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@32776
    17
  val max_threads: int Unsynchronized.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@32295
    24
  val with_attributes: Thread.threadAttribute list -> (Thread.threadAttribute list -> 'a) -> 'a
wenzelm@32295
    25
  val sync_wait: Thread.threadAttribute list option -> Time.time option ->
wenzelm@32295
    26
    ConditionVar.conditionVar -> Mutex.mutex -> bool Exn.result
wenzelm@32777
    27
  val trace: int Unsynchronized.ref
wenzelm@32295
    28
  val tracing: int -> (unit -> string) -> unit
wenzelm@32295
    29
  val tracing_time: bool -> Time.time -> (unit -> string) -> unit
wenzelm@32295
    30
  val real_time: ('a -> unit) -> 'a -> Time.time
wenzelm@24690
    31
  val self_critical: unit -> bool
wenzelm@25704
    32
  val serial: unit -> int
wenzelm@24690
    33
end;
wenzelm@24690
    34
wenzelm@24690
    35
structure Multithreading: MULTITHREADING =
wenzelm@24690
    36
struct
wenzelm@24690
    37
wenzelm@32185
    38
(* options *)
wenzelm@24690
    39
wenzelm@24690
    40
val available = false;
wenzelm@32777
    41
val max_threads = Unsynchronized.ref (1: int);
wenzelm@28460
    42
fun max_threads_value () = 1: int;
wenzelm@28554
    43
fun enabled () = false;
wenzelm@24690
    44
wenzelm@32286
    45
wenzelm@32286
    46
(* attributes *)
wenzelm@32286
    47
wenzelm@32295
    48
val no_interrupts = [];
wenzelm@32295
    49
val public_interrupts = [];
wenzelm@32295
    50
val private_interrupts = [];
wenzelm@32295
    51
fun sync_interrupts _ = [];
wenzelm@28187
    52
wenzelm@32295
    53
fun with_attributes _ e = e [];
wenzelm@28160
    54
wenzelm@32295
    55
fun sync_wait _ _ _ _ = Exn.Result true;
wenzelm@32295
    56
wenzelm@32295
    57
wenzelm@32295
    58
(* tracing *)
wenzelm@30612
    59
wenzelm@32777
    60
val trace = Unsynchronized.ref (0: int);
wenzelm@32295
    61
fun tracing _ _ = ();
wenzelm@32295
    62
fun tracing_time _ _ _ = ();
wenzelm@32295
    63
fun real_time f x = (f x; Time.zeroTime);
wenzelm@32286
    64
wenzelm@25735
    65
wenzelm@25735
    66
(* critical section *)
wenzelm@25735
    67
wenzelm@24690
    68
fun self_critical () = false;
wenzelm@24690
    69
fun NAMED_CRITICAL _ e = e ();
wenzelm@24690
    70
fun CRITICAL e = e ();
wenzelm@24690
    71
wenzelm@25735
    72
wenzelm@25735
    73
(* serial numbers *)
wenzelm@25735
    74
wenzelm@32777
    75
local val count = Unsynchronized.ref (0: int)
wenzelm@25704
    76
in fun serial () = (count := ! count + 1; ! count) end;
wenzelm@25704
    77
wenzelm@28123
    78
end;
wenzelm@28123
    79
wenzelm@32286
    80
structure Basic_Multithreading: BASIC_MULTITHREADING = Multithreading;
wenzelm@32286
    81
open Basic_Multithreading;