File: manual038.html

package info (click to toggle)
ocaml-doc 3.10-1
  • links: PTS, VCS
  • area: non-free
  • in suites: lenny
  • size: 7,476 kB
  • ctags: 2,644
  • sloc: ml: 325; sh: 64; makefile: 34; ansic: 15
file content (61 lines) | stat: -rw-r--r-- 3,752 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.09">
<LINK rel="stylesheet" type="text/css" href="manual.css">
<TITLE>The threads library</TITLE>
</HEAD>
<BODY >
<A HREF="manual037.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
<A HREF="manual039.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
<HR>
<H1 CLASS="chapter"><A NAME="htoc256">Chapter24</A>The threads library</H1><P>
<A NAME="c:threads"></A>
</P><P>The <TT>threads</TT> library allows concurrent programming in Objective Caml.
It provides multiple threads of control (also called lightweight
processes) that execute concurrently in the same memory space. Threads
communicate by in-place modification of shared data structures, or by
sending and receiving data on communication channels.</P><P>The <TT>threads</TT> library is implemented by time-sharing on a single
processor. It will not take advantage of multi-processor machines.
Using this library will therefore never make programs run
faster. However, many programs are easier to write when structured as
several communicating processes.</P><P>Two implementations of the <TT>threads</TT> library are available, depending
on the capabilities of the operating system:
</P><UL CLASS="itemize"><LI CLASS="li-itemize">
System threads. This implementation builds on the OS-provided threads
facilities: POSIX 1003.1c threads for Unix, and Win32 threads for
Windows. When available, system threads support both bytecode and
native-code programs.
</LI><LI CLASS="li-itemize">VM-level threads. This implementation performs time-sharing and
context switching at the level of the OCaml virtual machine (bytecode
interpreter). It is available on Unix systems, and supports only
bytecode programs. It cannot be used with native-code programs.
</LI></UL><P>
Programs that use system threads must be linked as follows:
</P><PRE>
        ocamlc -thread <I>other options</I> unix.cma threads.cma <I>other files</I>
        ocamlopt -thread <I>other options</I> unix.cmxa threads.cmxa <I>other files</I>
</PRE><P>
Compilation units that use the <TT>threads</TT> library must also be compiled with
the <TT>-thread</TT> option (see chapter<A HREF="manual022.html#c:camlc">8</A>).</P><P>Programs that use VM-level threads must be compiled with the <TT>-vmthread</TT>
option to <TT>ocamlc</TT> (see chapter<A HREF="manual022.html#c:camlc">8</A>), and be linked as follows:
</P><PRE>
        ocamlc -vmthread <I>other options</I> threads.cma <I>other files</I>
</PRE><P>
Compilation units that use <TT>threads</TT> library must also be compiled with
the <TT>-vmthread</TT> option (see chapter<A HREF="manual022.html#c:camlc">8</A>).</P><UL CLASS="ftoc2"><LI CLASS="li-links">
<A HREF="libref/Thread.html">Module <TT>Thread</TT>: lightweight threads</A>
</LI><LI CLASS="li-links"><A HREF="libref/Mutex.html">Module <TT>Mutex</TT>: locks for mutual exclusion</A>
</LI><LI CLASS="li-links"><A HREF="libref/Condition.html">Module <TT>Condition</TT>: condition variables to synchronize between threads</A>
</LI><LI CLASS="li-links"><A HREF="libref/Event.html">Module <TT>Event</TT>: first-class synchronous communication</A>
</LI><LI CLASS="li-links"><A HREF="libref/ThreadUnix.html">Module <TT>ThreadUnix</TT>: thread-compatible system calls</A>
</LI></UL><HR>
<A HREF="manual037.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
<A HREF="manual039.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>