1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2
"http://www.w3.org/TR/REC-html40/loose.dtd">
6
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7
<META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14">
12
<BODY TEXT=black BGCOLOR=white>
13
<A HREF="manual036.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
14
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
15
<A HREF="manual038.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
17
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
18
<TR><TD BGCOLOR="#2de52d"><DIV ALIGN=center><TABLE>
19
<TR><TD><A NAME="htoc228"><B><FONT SIZE=6>Chapter 23</FONT></B></A></TD>
20
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=6>The threads library</FONT></B></TD>
21
</TR></TABLE></DIV></TD>
23
<A NAME="c:threads"></A>
25
The <TT>threads</TT> library allows concurrent programming in Objective Caml.
26
It provides multiple threads of control (also called lightweight
27
processes) that execute concurrently in the same memory space. Threads
28
communicate by in-place modification of shared data structures, or by
29
sending and receiving data on communication channels.<BR>
31
The <TT>threads</TT> library is implemented by time-sharing on a single
32
processor. It will not take advantage of multi-processor machines.
33
Using this library will therefore never make programs run
34
faster. However, many programs are easier to write when structured as
35
several communicating processes.<BR>
38
<FONT COLOR=purple>Unix:</FONT>
40
Programs that use the <TT>threads</TT> library must be linked as follows:
42
ocamlc -thread <I>other options</I> threads.cma <I>other files</I>
44
The <TT>-thread</TT> option selects a special, thread-safe version of
45
the standard library (see chapter <A HREF="manual022.html#c:camlc">8</A>). The <TT>-thread</TT>
46
option must also be given when compiling any source file that
47
references modules from the thread library (<TT>Thread</TT>, <TT>Mutex</TT>, ...).<BR>
49
The default thread implementation cannot be used in native-code
50
programs compiled with <TT>ocamlopt</TT>. If your operating system provides
51
POSIX 1003.1c compliant threads, you can select an alternate
52
implementation when configuring Objective Caml (use the
53
<TT>-with-pthread</TT> option to <TT>configure</TT>) which also supports native-code
54
programs. Programs that use this alternate implementation of the
55
<TT>threads</TT> library must be linked as follows:
57
ocamlc -thread <I>other options</I> threads.cma <I>other files</I>
58
ocamlopt -thread <I>other options</I> threads.cmxa <I>other files</I>
60
Depending on the operating system, extra system libraries can be
61
necessary. For instance, under Solaris 2.5, add <TT>-cclib -lposix4</TT>
62
at the end of the command line.
65
<FONT COLOR=purple>Windows:</FONT>
67
Programs that use the <TT>threads</TT> library must be linked as follows:
69
ocamlc -thread <I>other options</I> threads.cma <I>other files</I>
71
All object files on the command line must also have been compiled with
72
the <TT>-thread</TT> option, which selects a special, thread-safe version of
73
the standard library (see chapter <A HREF="manual022.html#c:camlc">8</A>).
77
<li><a HREF=libref/Thread.html> Module <tt>Thread</tt>: lightweight threads</a></li>
78
<li><a HREF=libref/Mutex.html> Module <tt>Mutex</tt>: locks for mutual exclusion</a></li>
79
<li><a HREF=libref/Condition.html> Module <tt>Condition</tt>: condition variables to synchronize between threads</a></li>
80
<li><a HREF=libref/Event.html> Module <tt>Event</tt>: first-class synchronous communication</a></li>
81
<li><a HREF=libref/ThreadUnix.html> Module <tt>ThreadUnix</tt>: thread-compatible system calls</a></li>
87
<A HREF="manual036.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
88
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
89
<A HREF="manual038.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>