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;
     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 available: bool
    17   val max_threads: int ref
    18   val max_threads_value: unit -> int
    19   val enabled: unit -> bool
    20   val no_interrupts: Thread.threadAttribute list
    21   val public_interrupts: Thread.threadAttribute list
    22   val private_interrupts: Thread.threadAttribute list
    23   val sync_interrupts: Thread.threadAttribute list -> Thread.threadAttribute list
    24   val interrupted: unit -> unit  (*exception Interrupt*)
    25   val with_attributes: Thread.threadAttribute list -> (Thread.threadAttribute list -> 'a) -> 'a
    26   val sync_wait: Thread.threadAttribute list option -> Time.time option ->
    27     ConditionVar.conditionVar -> Mutex.mutex -> bool Exn.result
    28   val trace: int ref
    29   val tracing: int -> (unit -> string) -> unit
    30   val tracing_time: bool -> Time.time -> (unit -> string) -> unit
    31   val real_time: ('a -> unit) -> 'a -> Time.time
    32   val self_critical: unit -> bool
    33   val serial: unit -> int
    34 end;
    35 
    36 structure Multithreading: MULTITHREADING =
    37 struct
    38 
    39 (* options *)
    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 
    47 (* attributes *)
    48 
    49 val no_interrupts = [];
    50 val public_interrupts = [];
    51 val private_interrupts = [];
    52 fun sync_interrupts _ = [];
    53 
    54 fun interrupted () = ();
    55 
    56 fun with_attributes _ e = e [];
    57 
    58 fun sync_wait _ _ _ _ = Exn.Res true;
    59 
    60 
    61 (* tracing *)
    62 
    63 val trace = ref (0: int);
    64 fun tracing _ _ = ();
    65 fun tracing_time _ _ _ = ();
    66 fun real_time f x = (f x; Time.zeroTime);
    67 
    68 
    69 (* critical section *)
    70 
    71 fun self_critical () = false;
    72 fun NAMED_CRITICAL _ e = e ();
    73 fun CRITICAL e = e ();
    74 
    75 
    76 (* serial numbers *)
    77 
    78 local val count = ref (0: int)
    79 in fun serial () = (count := ! count + 1; ! count) end;
    80 
    81 end;
    82 
    83 structure Basic_Multithreading: BASIC_MULTITHREADING = Multithreading;
    84 open Basic_Multithreading;