text
stringlengths
0
601k
let active_group_count group = Java . call " ThreadGroup . activeGroupCount ( activeGroupCount ) activeGroupCount " group
let destroy group = Java . call " ThreadGroup . destroy ( destroy ) destroy " group
let get_max_priority group = Java . call " ThreadGroup . getMaxPriority ( getMaxPriority ) getMaxPriority " group
let get_name group = Java . call " ThreadGroup . getName ( getName ) getName " group
let get_parent group = Java . call " ThreadGroup . getParent ( getParent ) getParent " group
let interrupt group = Java . call " ThreadGroup . interrupt ( interrupt ) interrupt " group
let is_daemon group = Java . call " ThreadGroup . isDaemon ( isDaemon ) isDaemon " group
let is_destroyed group = Java . call " ThreadGroup . isDestroyed ( isDestroyed ) isDestroyed " group
let parent_of group1 group2 = Java . call " ThreadGroup . parentOf ( parentOfThreadGroup ) parentOfThreadGroup " group1 group2
let set_daemon group b = Java . call " ThreadGroup . setDaemon ( setDaemonboolean ) setDaemonboolean " group b
let set_max_priority group prio = Java . call " ThreadGroup . setMaxPriority ( setMaxPriorityint ) setMaxPriorityint " group prio
let enumerate_threads group ( ? recurse = true ) true dest = Java . call " ThreadGroup . enumerate ( enumerateThread [ enumerateThread ] enumerateThread , boolean ) boolean " group dest recurse
let enumerate_groups group ( ? recurse = true ) true dest = Java . call " ThreadGroup . enumerate ( enumerateThreadGroup [ enumerateThreadGroup ] enumerateThreadGroup , boolean ) boolean " group dest recurse " java null "
let null = null ( ) " java is_null " " java is_not_null "
let wrap x = if is_null x then None else Some x
let unwrap = function | Some x -> x | None -> null
let ( let ) + xs f = List . map f xs
let get_current ( ask : Queries . ask ) : ThreadLifted . t = ask . f Queries . CurrentThreadId
let get_current_unlift ask : Thread . t = match get_current ask with | ` Lifted thread -> thread | _ -> failwith " ThreadId . get_current_unlift "
module Spec = struct include Analyses . DefaultSpec module TD = Thread . D module D = Lattice . Prod ( ThreadLifted ) ( TD ) module C = D let tids = ref ( Hashtbl . create 20 ) let name ( ) = " threadid " let startstate v = ( ThreadLifted . bot ( ) , TD . bot ( ) ) let exitstate v = ( ` Lifted ( Thread . threadinit v ~...
let _ = MCP . register_analysis ( module Spec : MCPSpec )
module type S = sig include Printable . S include MapDomain . Groupable with type t := t val threadinit : varinfo -> multiple : bool -> t val is_main : t -> bool val is_unique : t -> bool val may_create : t -> t -> bool val is_must_parent : t -> t -> bool end
module type Stateless = sig include S val threadenter : Node . t -> varinfo -> t end
module type Stateful = sig include S module D : Lattice . S val threadenter : t * D . t -> Node . t -> varinfo -> t list val threadspawn : D . t -> Node . t -> varinfo -> D . t val created : t -> D . t -> ( t list ) option end
module FunNode : Stateless = struct include Printable . Prod ( CilType . Varinfo ) ( Printable . Option ( Node ) ( struct let name = " no node " end ) ) let show = function | ( f , Some n ) -> f . vname ^ " " @ ^ ( CilType . Location . show ( UpdateCil . getLoc n ) ) | ( f , None ) -> f . vname include Printable . Simp...
module Unit ( Base : Stateless ) : Stateful = struct include Base module D = Lattice . Unit let threadenter _ n v = [ threadenter n v ] let threadspawn ( ) _ _ = ( ) let created _ _ = None end
module History ( Base : Stateless ) : Stateful = struct module P = struct include Printable . Liszt ( Base ) let name ( ) = " prefix " end module S = struct include SetDomain . Make ( Base ) let name ( ) = " set " end include Printable . Prod ( P ) ( S ) let pretty ( ) ( p , s ) = let p = List . rev p in if S . is_empt...
module ThreadLiftNames = struct let bot_name = " Bot Threads " let top_name = " Top Threads " end
module Lift ( Thread : S ) = struct include Lattice . Flat ( Thread ) ( ThreadLiftNames ) let name ( ) = " Thread " end
module FlagConfiguredTID : Stateful = struct module H = History ( FunNode ) module P = Unit ( FunNode ) include GroupableFlagHelper ( H ) ( P ) ( struct let msg = " FlagConfiguredTID received a value where not exactly one component is set " let name = " FlagConfiguredTID " end ) module D = Lattice . Lift2 ( H . D ) ( P...
module ThreadLifted = Lift ( Thread )
module Spec = struct include Analyses . IdentitySpec let name ( ) = " threadJoins " module D = MustTIDs module C = D module G = MustTIDs module V = TID let return ctx ( exp : exp option ) ( f : fundec ) : D . t = ( match ctx . ask CurrentThreadId with | ` Lifted tid -> ctx . sideg tid ctx . local | _ -> ( ) ) ; ctx . l...
let _ = MCP . register_analysis ~ dep [ " : threadid " ] ( module Spec : MCPSpec )
type ' a t = _ ' ThreadLocal java_instance " ocamljava_threadlocal_make " " ocamljava_threadlocal_get " " ocamljava_threadlocal_remove " " ocamljava_threadlocal_set " " java null "
let null = null ( ) " java is_null " " java is_not_null "
let wrap x = if is_null x then None else Some x
let unwrap = function | Some x -> x | None -> null
type t = _ ' ThreadPoolExecutor java_instance " ocamljava_threadpoolexecutor_make "
let make ~ core_pool_size ~ max_pool_size time timeunit rhe = threadpoolexecutor_make core_pool_size max_pool_size time timeunit rhe
let await_termination tpe time timeunit = Java . call " ThreadPoolExecutor . awaitTermination ( awaitTerminationlong , TimeUnit ) TimeUnit " tpe time timeunit
let get_active_count tpe = Java . call " ThreadPoolExecutor . getActiveCount ( getActiveCount ) getActiveCount " tpe
let get_completed_task_count tpe = Java . call " ThreadPoolExecutor . getCompletedTaskCount ( getCompletedTaskCount ) getCompletedTaskCount " tpe
let get_core_pool_size tpe = Java . call " ThreadPoolExecutor . getCorePoolSize ( getCorePoolSize ) getCorePoolSize " tpe
let get_keep_alive_time tpe timeunit = Java . call " ThreadPoolExecutor . getKeepAliveTime ( getKeepAliveTimeTimeUnit ) getKeepAliveTimeTimeUnit " tpe timeunit
let get_largest_pool_size tpe = Java . call " ThreadPoolExecutor . getLargestPoolSize ( getLargestPoolSize ) getLargestPoolSize " tpe
let get_maximum_pool_size tpe = Java . call " ThreadPoolExecutor . getMaximumPoolSize ( getMaximumPoolSize ) getMaximumPoolSize " tpe
let get_pool_size tpe = Java . call " ThreadPoolExecutor . getPoolSize ( getPoolSize ) getPoolSize " tpe
let get_rejected_execution_handler tpe = Java . call " ThreadPoolExecutor . getRejectedExecutionHandler ( getRejectedExecutionHandler ) getRejectedExecutionHandler " tpe
let get_task_count tpe = Java . call " ThreadPoolExecutor . getTaskCount ( getTaskCount ) getTaskCount " tpe " ocamljava_threadpoolexecutor_invoke_all " " ocamljava_threadpoolexecutor_invoke_all_time " " ocamljava_threadpoolexecutor_invoke_any " " ocamljava_threadpoolexecutor_invoke_any_time "
let is_shutdown tpe = Java . call " ThreadPoolExecutor . isShutdown ( isShutdown ) isShutdown " tpe
let is_terminated tpe = Java . call " ThreadPoolExecutor . isTerminated ( isTerminated ) isTerminated " tpe
let is_terminating tpe = Java . call " ThreadPoolExecutor . isTerminating ( isTerminating ) isTerminating " tpe
let set_core_pool_size tpe sz = Java . call " ThreadPoolExecutor . setCorePoolSize ( setCorePoolSizeint ) setCorePoolSizeint " tpe sz
let set_keep_alive_time tpe time timeunit = Java . call " ThreadPoolExecutor . setKeepAliveTime ( setKeepAliveTimelong , TimeUnit ) TimeUnit " tpe time timeunit
let set_maximum_pool_size tpe sz = Java . call " ThreadPoolExecutor . setMaximumPoolSize ( setMaximumPoolSizeint ) setMaximumPoolSizeint " tpe sz
let set_rejected_execution_handler tpe reh = Java . call " ThreadPoolExecutor . setRejectedExecutionHandler ( setRejectedExecutionHandlerRejectedExecutionHandler ) setRejectedExecutionHandlerRejectedExecutionHandler " tpe reh
let shutdown tpe = Java . call " ThreadPoolExecutor . shutdown ( shutdown ) shutdown " tpe " ocamljava_threadpoolexecutor_shutdown_now " " ocamljava_threadpoolexecutor_submit " " java null "
let null = null ( ) " java is_null " " java is_not_null "
let wrap x = if is_null x then None else Some x
let unwrap = function | Some x -> x | None -> null
let is_current ( ask : Queries . ask ) : bool = ask . f Queries . MayBeThreadReturn
module Spec : Analyses . MCPSpec = struct include Analyses . DefaultSpec let name ( ) = " threadreturn " module D = IntDomain . Booleans module C = D let assign ctx ( lval : lval ) ( rval : exp ) : D . t = ctx . local let branch ctx ( exp : exp ) ( tv : bool ) : D . t = ctx . local let body ctx ( f : fundec ) : D . t =...
let _ = MCP . register_analysis ( module Spec : MCPSpec )
let stopped = ref false
let rec loop ( ) = let rec generate_list n = let rec aux acc = function | 0 -> acc | n -> aux ( float n :: acc ) ( n - 1 ) in aux [ ] n in let long_list = generate_list 100000 in let res = List . length ( List . rev_map sin long_list ) in ignore ( Sys . opaque_identity res )
let thread s = ignore ( Thread . sigmask Unix . SIG_UNBLOCK [ s ] ) ; while not ! stopped do loop ( ) done
let handler tid_exp cnt signal = incr cnt ; if Thread . id ( Thread . self ( ) ) != ! tid_exp then Printf . printf " Signal received in an unexpected thread !\ n "
let _ = ignore ( Thread . sigmask Unix . SIG_BLOCK [ Sys . sigusr1 ; Sys . sigusr2 ] ) ; let ( tid1 , tid2 ) = ( ref 0 , ref 0 ) in let ( cnt1 , cnt2 ) = ( ref 0 , ref 0 ) in Sys . set_signal Sys . sigusr1 ( Sys . Signal_handle ( handler tid1 cnt1 ) ) ; Sys . set_signal Sys . sigusr2 ( Sys . Signal_handle ( handler tid...
let timed_read fd buff ofs len timeout = if Thread . wait_timed_read fd timeout then Unix . read fd buff ofs len else raise ( Unix_error ( ETIMEDOUT , " timed_read " , " " ) )
let timed_write fd buff ofs len timeout = if Thread . wait_timed_write fd timeout then Unix . write fd buff ofs len else raise ( Unix_error ( ETIMEDOUT , " timed_write " , " " ) )
let timed_write_substring fd buff ofs len timeout = timed_write fd ( Bytes . unsafe_of_string buff ) ofs len timeout
let log_delays thunk = let start = Time . now ( ) in let print_time ( ) = let diff = Time . diff ( Time . now ( ) ) start in Caml . Printf . printf " . " ; %! printf " % s , " ( Time . Span . to_string diff ) in let d = thunk ( ) in Clock . every ( sec 0 . 1 ) ~ stop : d print_time ; d >>| fun ( ) -> print_time ( ) ; p...
type how_to_wait = | After | Busyloop | Busyloop_in_thread | Noalloc_busyloop_in_thread | Noalloc_busyloop_in_thread_2
let busyloop ( ) = let x = ref None in for i = 1 to 50_000_000 do x := Some i done
let noalloc_busyloop ( ) = for _i = 1 to 50_000_000 do ( ) done
let noalloc_busyloop_2 ( ) = let rec loop i = if i = 0 then ( ) else loop ( i - 1 ) in loop 50_000_000
let wait_and_log how_to_wait = let until = match how_to_wait with | After -> ( fun ( ) -> after ( sec 1 . ) ) | Busyloop -> ( fun ( ) -> busyloop ( ) ; return ( ) ) | Busyloop_in_thread -> ( fun ( ) -> In_thread . run busyloop ) | Noalloc_busyloop_in_thread -> ( fun ( ) -> In_thread . run noalloc_busyloop ) | Noalloc_b...
let how_to_wait = Command . Spec . Arg_type . create ( fun s -> Sexp . of_string s |> how_to_wait_of_sexp )
let ( ) = Command . async_basic ~ summary " : run logger without busy loop " Command . Spec . ( empty +> anon ( " how - to - wait " %: how_to_wait ) ) ( fun how ( ) -> wait_and_log how ) |> Command . run
let thread_main ( ) = printf " Start of thread_main \ n " ; %! failwith " exception thrown out of thread_main "
let main ~ create_thread ~ join_thread = Core . at_exit ( fun ( ) -> printf " Core . at_exit callback ran \ n " ) ; %! Caml . at_exit ( fun ( ) -> printf " Caml . at_exit callback ran \ n " ) ; %! printf " About to create thread \ n " ; %! let thread = create_thread thread_main ( ) in join_thread thread ; printf " Thre...
let core_command = Command . basic ~ summary " : Test Core . Thread . create ' s ~ on_uncaught_exn argument " [ % map_open . Command let on_uncaught_exn = let arg_type = Command . Arg_type . of_alist_exn [ " print - to - stderr " , ` Print_to_stderr ; " kill - whole - process " , ` Kill_whole_process ] in flag " - on -...
let caml_command = let main ( ) = main ~ create_thread : Caml . Thread . create ~ join_thread : Caml . Thread . join in Command . basic ~ summary " : Test Caml . Thread . create ' s behaviour when exns are thrown " ( Command . Param . return main )
let command = Command . group ~ summary " : Demonstrate behaviour when exns are thrown out of Thread . create " [ " core " , core_command ; " caml " , caml_command ]
let ( ) = Command . run command
type t = { max_threads : int ; lock : Mutex . t ; condition : Condition . t ; table : ( int , Thread . t ) Hashtbl . t ; }
let create ( ? max_threads = 128 ) ( ) = { max_threads ; lock = Mutex . create ( ) ; condition = Condition . create ( ) ; table = Hashtbl . create max_threads ; }
let signal_work_done thread_id pool = Mutex . lock pool . lock ; try Hashtbl . remove pool . table thread_id ; Condition . signal pool . condition ; Mutex . unlock pool . lock with _ -> Mutex . unlock pool . lock
let add_work f x pool = Mutex . lock pool . lock ; try while Hashtbl . length pool . table >= pool . max_threads do Condition . wait pool . condition pool . lock done ; let f ' x = let thread = Thread . self ( ) in let thread_id = Thread . id thread in let _ = f x in signal_work_done thread_id pool in let thread = Thre...
let shutdown pool = Hashtbl . iter ( fun _ thread -> Thread . join thread ) pool . table
let create fn arg = thread_new ( fun ( ) -> try fn arg ; ( ) with exn -> flush stdout ; flush stderr ; thread_uncaught_exception exn )
let kill th = invalid_arg " Thread . kill : not implemented "
let preempt signal = yield ( )
let _ = ignore ( Sys . signal Sys . sigvtalrm ( Sys . Signal_handle preempt ) ) ; thread_initialize ( )
let delay time = ignore ( Unix . select [ ] [ ] [ ] time )
let wait_read fd = ( )
let wait_write fd = ( )
let wait_timed_read fd d = match Unix . select [ fd ] [ ] [ ] d with ( [ ] , _ , _ ) -> false | ( _ , _ , _ ) -> true
let wait_timed_write fd d = match Unix . select [ ] [ fd ] [ ] d with ( _ , [ ] , _ ) -> false | ( _ , _ , _ ) -> true
let wait_pid p = Unix . waitpid [ ] p