src/Pure/ML-Systems/multithreading.ML
author wenzelm
Tue, 09 Sep 2008 23:48:36 +0200
changeset 28187 4062882c7df3
parent 28169 356fc8734741
child 28460 455ef74607d7
permissions -rw-r--r--
proper values of no_interrupts, regular_interrupts;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/multithreading.ML
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
     4
28149
26bd1245a46b added no_interrupts;
wenzelm
parents: 28123
diff changeset
     5
Dummy implementation of multithreading setup.
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
     6
*)
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
     7
25704
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
     8
signature BASIC_MULTITHREADING =
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
     9
sig
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    10
  val NAMED_CRITICAL: string -> (unit -> 'a) -> 'a
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    11
  val CRITICAL: (unit -> 'a) -> 'a
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    12
end;
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    13
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    14
signature MULTITHREADING =
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    15
sig
25704
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    16
  include BASIC_MULTITHREADING
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    17
  val trace: int ref
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    18
  val tracing: int -> (unit -> string) -> unit
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    19
  val available: bool
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    20
  val max_threads: int ref
25775
90525e67ede7 added Multithreading.max_threads_value, which maps a value of 0 to number of CPUs;
wenzelm
parents: 25735
diff changeset
    21
  val max_threads_value: unit -> int
28149
26bd1245a46b added no_interrupts;
wenzelm
parents: 28123
diff changeset
    22
  val no_interrupts: Thread.threadAttribute list
28160
e0177b67ecd9 added sync_interrupts, regular_interrupts;
wenzelm
parents: 28149
diff changeset
    23
  val regular_interrupts: Thread.threadAttribute list
e0177b67ecd9 added sync_interrupts, regular_interrupts;
wenzelm
parents: 28149
diff changeset
    24
  val with_attributes: Thread.threadAttribute list ->
e0177b67ecd9 added sync_interrupts, regular_interrupts;
wenzelm
parents: 28149
diff changeset
    25
    (Thread.threadAttribute list -> 'a -> 'b) -> 'a -> 'b
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    26
  val self_critical: unit -> bool
25704
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    27
  val serial: unit -> int
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    28
end;
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    29
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    30
structure Multithreading: MULTITHREADING =
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    31
struct
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    32
25735
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    33
(* options *)
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    34
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    35
val trace = ref (0: int);
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    36
fun tracing _ _ = ();
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    37
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    38
val available = false;
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    39
val max_threads = ref (1: int);
25775
90525e67ede7 added Multithreading.max_threads_value, which maps a value of 0 to number of CPUs;
wenzelm
parents: 25735
diff changeset
    40
fun max_threads_value () = Int.max (! max_threads, 1);
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    41
28187
4062882c7df3 proper values of no_interrupts, regular_interrupts;
wenzelm
parents: 28169
diff changeset
    42
val no_interrupts =
4062882c7df3 proper values of no_interrupts, regular_interrupts;
wenzelm
parents: 28169
diff changeset
    43
  [Thread.EnableBroadcastInterrupt false, Thread.InterruptState Thread.InterruptDefer];
4062882c7df3 proper values of no_interrupts, regular_interrupts;
wenzelm
parents: 28169
diff changeset
    44
4062882c7df3 proper values of no_interrupts, regular_interrupts;
wenzelm
parents: 28169
diff changeset
    45
val regular_interrupts =
4062882c7df3 proper values of no_interrupts, regular_interrupts;
wenzelm
parents: 28169
diff changeset
    46
  [Thread.EnableBroadcastInterrupt true, Thread.InterruptState Thread.InterruptAsynchOnce];
28160
e0177b67ecd9 added sync_interrupts, regular_interrupts;
wenzelm
parents: 28149
diff changeset
    47
e0177b67ecd9 added sync_interrupts, regular_interrupts;
wenzelm
parents: 28149
diff changeset
    48
fun with_attributes _ f x = f [] x;
28149
26bd1245a46b added no_interrupts;
wenzelm
parents: 28123
diff changeset
    49
25735
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    50
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    51
(* critical section *)
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    52
24690
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    53
fun self_critical () = false;
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    54
fun NAMED_CRITICAL _ e = e ();
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    55
fun CRITICAL e = e ();
c661dae1070a renamed ML-Systems/multithreading_dummy.ML to ML-Systems/multithreading.ML;
wenzelm
parents:
diff changeset
    56
25735
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    57
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    58
(* serial numbers *)
4d147263f71f added get/put_data;
wenzelm
parents: 25704
diff changeset
    59
25704
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    60
local val count = ref (0: int)
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    61
in fun serial () = (count := ! count + 1; ! count) end;
df9c8074ff09 signature BASIC_MULTITHREADING;
wenzelm
parents: 24690
diff changeset
    62
28123
53cd972d7db9 provide dummy thread structures, including proper Thread.getLocal/setLocal;
wenzelm
parents: 26082
diff changeset
    63
end;
53cd972d7db9 provide dummy thread structures, including proper Thread.getLocal/setLocal;
wenzelm
parents: 26082
diff changeset
    64
53cd972d7db9 provide dummy thread structures, including proper Thread.getLocal/setLocal;
wenzelm
parents: 26082
diff changeset
    65
structure BasicMultithreading: BASIC_MULTITHREADING = Multithreading;
53cd972d7db9 provide dummy thread structures, including proper Thread.getLocal/setLocal;
wenzelm
parents: 26082
diff changeset
    66
open BasicMultithreading;