src/Pure/ML-Systems/multithreading.ML
author wenzelm
Sat Jul 25 00:13:39 2009 +0200 (2009-07-25 ago)
changeset 32184 cfa0ef0c0c5f
parent 30612 cb6421b6a18f
child 32185 57ecfab3bcfe
permissions -rw-r--r--
simplified/unified Multithreading.tracing_time;
tuned;
     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 tracing_time: Time.time -> (unit -> string) -> unit
    19   val available: bool
    20   val max_threads: int ref
    21   val max_threads_value: unit -> int
    22   val enabled: unit -> bool
    23   val no_interrupts: Thread.threadAttribute list
    24   val regular_interrupts: Thread.threadAttribute list
    25   val restricted_interrupts: Thread.threadAttribute list
    26   val with_attributes: Thread.threadAttribute list ->
    27     (Thread.threadAttribute list -> 'a -> 'b) -> 'a -> 'b
    28   val self_critical: unit -> bool
    29   val serial: unit -> int
    30 end;
    31 
    32 structure Multithreading: MULTITHREADING =
    33 struct
    34 
    35 (* options *)
    36 
    37 val trace = ref (0: int);
    38 fun tracing _ _ = ();
    39 fun tracing_time _ _ = ();
    40 
    41 val available = false;
    42 val max_threads = ref (1: int);
    43 fun max_threads_value () = 1: int;
    44 fun enabled () = false;
    45 
    46 val no_interrupts =
    47   [Thread.EnableBroadcastInterrupt false, Thread.InterruptState Thread.InterruptDefer];
    48 
    49 val regular_interrupts =
    50   [Thread.EnableBroadcastInterrupt true, Thread.InterruptState Thread.InterruptAsynchOnce];
    51 
    52 val restricted_interrupts =
    53   [Thread.EnableBroadcastInterrupt false, Thread.InterruptState Thread.InterruptAsynchOnce];
    54 
    55 fun with_attributes _ f x = f [] x;
    56 
    57 
    58 (* critical section *)
    59 
    60 fun self_critical () = false;
    61 fun NAMED_CRITICAL _ e = e ();
    62 fun CRITICAL e = e ();
    63 
    64 
    65 (* serial numbers *)
    66 
    67 local val count = ref (0: int)
    68 in fun serial () = (count := ! count + 1; ! count) end;
    69 
    70 end;
    71 
    72 structure BasicMultithreading: BASIC_MULTITHREADING = Multithreading;
    73 open BasicMultithreading;