Module Async_unix__.In_thread
module Priority : module type of Core.Linux_ext.Priority with type Priority.t = Core.Linux_ext.Priority.tmodule Helper_thread : sig ... endval pipe_of_squeue : 'a Squeue.t -> 'a Async_kernel.Pipe.Reader.tpipe_of_squeue squeuereturns a pipepand consumes the contentssqueue, placing them inp. It repeatedly grabs everything fromsqueue, places it inp, and then waits for pushback onp.
module When_finished : sig ... endWhen_finisheddescribes howIn_thread.run fbehaves when the helper thread finishesf ().
val run : ?priority:Priority.t -> ?thread:Helper_thread.t -> ?when_finished:When_finished.t -> ?name:string -> (unit -> 'a) -> 'a Async_kernel.Deferred.trun ?priority ?thread ?name frunsf ()in a separate thread outside Async and returns the result as a Deferred in the Async world. Iff ()raises an exception (asynchronously, since it is another thread) then that exception will be raised to the monitor that calledrun.WARNING: Async code MUST NOT be used from within
f. By Async code we mean pretty-much all functions of libraries making use of Async. Only a few functions of the Async library can be called insideIn_thread.run. These are explicitly marked as such, using the phrase "thread-safe".If
threadis not supplied, then any thread from the thread pool could be used. If you need to run routines in a specific thread (as is required by some libraries like Sqlite), you should create a helper thread and supply it torun.If
priorityis supplied, the priority of the thread in the linux scheduler will be set topriorityfor the duration off (), provided the thread is allowed to do so (seeman setpriority).If you call
runseveral times with the same helper thread, thef ()calls will run in sequence, in the order in which they are supplied torun. Eachf ()will complete (return or raise) before anotherf ()starts.For example, if you do:
let () = run ~thread f1; run ~thread f2; run ~thread f3;Then the thread will run
f1 ()to completion, thenf2 ()to completion, thenf3 ()to completion.If
nameis supplied, the name of the thread will be set to it for the duration of the execution off ().when_finisheddescribes how the helper thread behaves oncef ()has completed. Its default value is the value ofWhen_finished.defaultwhenrunis called.
val syscall : name:string -> (unit -> 'a) -> ('a, exn) Core.Result.t Async_kernel.Deferred.tsyscall fruns f, which should be a single system call, and returns the result, handling the restarting of interrupted system calls. To avoid race conditions, thefsupplied tosyscallshould just make a system call. That way, everything else is done holding the Async lock.
val syscall_exn : name:string -> (unit -> 'a) -> 'a Async_kernel.Deferred.t