src/Pure/ML-Systems/multithreading.ML
author wenzelm
Mon Jan 19 19:38:03 2009 +0100 (2009-01-19)
changeset 29564 f8b933a62151
parent 28554 a6065ce44984
child 30612 cb6421b6a18f
permissions -rw-r--r--
removed Ids;
     1 (*  Title:      Pure/ML-Systems/multithreading.ML
     2     Author:     Makarius
     3 
     4 Dummy implementation of multithreading setup.
     5 *)
     6 
     7 signature BASIC_MULTITHREADING =
     8 sig
     9   val NAMED_CRITICAL: string -> (unit -> 'a) -> 'a
    10   val CRITICAL: (unit -> 'a) -> 'a
    11 end;
    12 
    13 signature MULTITHREADING =
    14 sig
    15   include BASIC_MULTITHREADING
    16   val trace: int ref
    17   val tracing: int -> (unit -> string) -> unit
    18   val available: bool
    19   val max_threads: int ref
    20   val max_threads_value: unit -> int
    21   val enabled: unit -> bool
    22   val no_interrupts: Thread.threadAttribute list
    23   val regular_interrupts: Thread.threadAttribute list
    24   val with_attributes: Thread.threadAttribute list ->
    25     (Thread.threadAttribute list -> 'a -> 'b) -> 'a -> 'b
    26   val self_critical: unit -> bool
    27   val serial: unit -> int
    28 end;
    29 
    30 structure Multithreading: MULTITHREADING =
    31 struct
    32 
    33 (* options *)
    34 
    35 val trace = ref (0: int);
    36 fun tracing _ _ = ();
    37 
    38 val available = false;
    39 val max_threads = ref (1: int);
    40 fun max_threads_value () = 1: int;
    41 fun enabled () = false;
    42 
    43 val no_interrupts =
    44   [Thread.EnableBroadcastInterrupt false, Thread.InterruptState Thread.InterruptDefer];
    45 
    46 val regular_interrupts =
    47   [Thread.EnableBroadcastInterrupt true, Thread.InterruptState Thread.InterruptAsynchOnce];
    48 
    49 fun with_attributes _ f x = f [] x;
    50 
    51 
    52 (* critical section *)
    53 
    54 fun self_critical () = false;
    55 fun NAMED_CRITICAL _ e = e ();
    56 fun CRITICAL e = e ();
    57 
    58 
    59 (* serial numbers *)
    60 
    61 local val count = ref (0: int)
    62 in fun serial () = (count := ! count + 1; ! count) end;
    63 
    64 end;
    65 
    66 structure BasicMultithreading: BASIC_MULTITHREADING = Multithreading;
    67 open BasicMultithreading;