<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Thread_pool.html"> <link rel="next" href="Thread_safe_pipe.html"> <link rel="Up" href="index.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="Async_print" rel="Chapter" href="Async_print.html"> <link title="Async_sys" rel="Chapter" href="Async_sys.html"> <link title="Epoll_file_descr_watcher" rel="Chapter" href="Epoll_file_descr_watcher.html"> <link title="Fd" rel="Chapter" href="Fd.html"> <link title="Fd_by_descr" rel="Chapter" href="Fd_by_descr.html"> <link title="File_descr_watcher_intf" rel="Chapter" href="File_descr_watcher_intf.html"> <link title="Import" rel="Chapter" href="Import.html"> <link title="Interruptor" rel="Chapter" href="Interruptor.html"> <link title="In_thread" rel="Chapter" href="In_thread.html"> <link title="Io_stats" rel="Chapter" href="Io_stats.html"> <link title="Process" rel="Chapter" href="Process.html"> <link title="Raw_fd" rel="Chapter" href="Raw_fd.html"> <link title="Raw_scheduler" rel="Chapter" href="Raw_scheduler.html"> <link title="Raw_signal_manager" rel="Chapter" href="Raw_signal_manager.html"> <link title="Reader" rel="Chapter" href="Reader.html"> <link title="Read_write" rel="Chapter" href="Read_write.html"> <link title="Scheduler" rel="Chapter" href="Scheduler.html"> <link title="Select_file_descr_watcher" rel="Chapter" href="Select_file_descr_watcher.html"> <link title="Shutdown" rel="Chapter" href="Shutdown.html"> <link title="Signal" rel="Chapter" href="Signal.html"> <link title="Signal_manager" rel="Chapter" href="Signal_manager.html"> <link title="Std" rel="Chapter" href="Std.html"> <link title="Syscall" rel="Chapter" href="Syscall.html"> <link title="Thread_pool" rel="Chapter" href="Thread_pool.html"> <link title="Thread_safe" rel="Chapter" href="Thread_safe.html"> <link title="Thread_safe_pipe" rel="Chapter" href="Thread_safe_pipe.html"> <link title="Unix_syscalls" rel="Chapter" href="Unix_syscalls.html"> <link title="Writer" rel="Chapter" href="Writer.html"><title>Thread_safe</title> </head> <body> <div class="navbar"><a class="pre" href="Thread_pool.html" title="Thread_pool">Previous</a> <a class="up" href="index.html" title="Index">Up</a> <a class="post" href="Thread_safe_pipe.html" title="Thread_safe_pipe">Next</a> </div> <h1>Module <a href="type_Thread_safe.html">Thread_safe</a></h1> <pre><span class="keyword">module</span> Thread_safe: <code class="code">sig</code> <a href="Thread_safe.html">..</a> <code class="code">end</code></pre><div class="info module top"> The <code class="code">Thread_safe</code> module has functions that are safe to call from threads outside async. <p> All the <code class="code">Thread_safe.block*</code> and <code class="code">Thread_safe.run*</code> functions wake up the async scheduler to ensure that it continues in a timely manned with whatever jobs got started. Some functions take an optional <code class="code">?wakeup_scheduler:bool</code> argument, which defaults to <code class="code">true</code>. One can cause the scheduler to not be woken up by supplying <code class="code">~wakeup_scheduler:false</code>, which can reduce CPU use, but increase latency, because the scheduler may not wake up for a while to process jobs.<br> </div> <hr width="100%"> <pre><span id="VALam_holding_async_lock"><span class="keyword">val</span> am_holding_async_lock</span> : <code class="type">unit -> bool</code></pre><div class="info "> <code class="code">am_holding_async_lock ()</code> returns true if the currently running thread is holding the async lock.<br> </div> <pre><span id="VALdeferred"><span class="keyword">val</span> deferred</span> : <code class="type">unit -> 'a Async_core.Deferred.t * ('a -> unit)</code></pre><div class="info "> <code class="code">deferred ()</code> returns <code class="code">(d, fill)</code> where <code class="code">d</code> is a deferred that will become determined with value <code class="code">v</code> once <code class="code">fill v</code> is called. <p> It is ok to call <code class="code">deferred</code> from inside or outside async. <code class="code">fill</code> must be called from outside async.<br> </div> <pre><span id="VALrun_in_async_with_optional_cycle"><span class="keyword">val</span> run_in_async_with_optional_cycle</span> : <code class="type">?wakeup_scheduler:bool -><br> (unit -> [ `Do_not_run_a_cycle | `Run_a_cycle ] * 'a) -><br> ('a, exn) Core.Std.Result.t</code></pre><div class="info "> <code class="code">run_in_async_with_optional_cycle f</code> acquires the async lock and runs <code class="code">f ()</code> while holding the lock. Depending on the result of <code class="code">f</code>, it may also run a cycle.<br> </div> <pre><span id="VALrun_in_async"><span class="keyword">val</span> run_in_async</span> : <code class="type">?wakeup_scheduler:bool -> (unit -> 'a) -> ('a, exn) Core.Std.Result.t</code></pre><div class="info "> <code class="code">run_in_async f</code> acquires the async lock and runs <code class="code">f ()</code> while holding the lock. It returns the result of <code class="code">f ()</code> to the outside world. The scheduler is woken up to ensures the code that depends on <code class="code">f ()</code> is run soon enough. <p> <code class="code">run_in_async</code> doesn't run a cycle. <p> <code class="code">run_in_async</code> does not automatically start the async scheduler. You still need to call <code class="code">Scheduler.go</code> elsewhere in your program.<br> </div> <pre><span id="VALrun_in_async_exn"><span class="keyword">val</span> run_in_async_exn</span> : <code class="type">?wakeup_scheduler:bool -> (unit -> 'a) -> 'a</code></pre> <pre><span id="VALblock_on_async"><span class="keyword">val</span> block_on_async</span> : <code class="type">(unit -> 'a Async_core.Deferred.t) -> ('a, exn) Core.Std.Result.t</code></pre><div class="info "> <code class="code">block_on_async f</code> runs <code class="code">f ()</code> in the async world and blocks until the result becomes determined. This function can be called from the main thread or from a thread outside async. <p> <code class="code">block_on_async</code> will run a cycle if the deferred isn't determined, in the hope that running the cycle will cause the deferred to become determined. <p> <code class="code">block_on_async</code> will automatically start the scheduler if it isn't already running.<br> </div> <pre><span id="VALblock_on_async_exn"><span class="keyword">val</span> block_on_async_exn</span> : <code class="type">(unit -> 'a Async_core.Deferred.t) -> 'a</code></pre> <pre><span id="VALrun_in_async_wait"><span class="keyword">val</span> run_in_async_wait</span> : <code class="type">(unit -> 'a Async_core.Deferred.t) -> ('a, exn) Core.Std.Result.t</code></pre><div class="info "> <code class="code">run_in_async_wait f</code> is like <code class="code">block_on_async f</code>, except that it must be called from a thread outside async. Upon returning from <code class="code">run_in_async_wait</code>, it is guaranteed that the caller does not have the async lock.<br> </div> <pre><span id="VALrun_in_async_wait_exn"><span class="keyword">val</span> run_in_async_wait_exn</span> : <code class="type">(unit -> 'a Async_core.Deferred.t) -> 'a</code></pre></body></html>