File: mutex.html

package info (click to toggle)
boost 1.27.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,908 kB
  • ctags: 26,546
  • sloc: cpp: 122,225; ansic: 10,956; python: 4,412; sh: 855; yacc: 803; makefile: 257; perl: 165; lex: 90; csh: 6
file content (129 lines) | stat: -rw-r--r-- 3,760 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<HTML>
<HEAD>
<TITLE>mutex - Mutex</TITLE>
<LINK HREF="../pool.css" REL="stylesheet" TYPE="text/css">
</HEAD>
<BODY>

<IMG SRC="../../../../c++boost.gif" WIDTH=276 HEIGHT=86 ALT="C++ Boost">

<H1 ALIGN=CENTER>mutex - Mutex</H1>

<P>
<H2>Introduction</H2>

<P>
detail/mutex.hpp provides several mutex types that provide a consistent interface for OS-supplied mutex types.  These are all thread-level mutexes; interprocess mutexes are not supported.

<P>
<H2>Configuration</H2>

<P>
This header file will try to guess what kind of system it is on.  It will auto-configure itself for Win32 or POSIX+pthread systems.  To stub out all mutex code, bypassing the auto-configuration, <SPAN CLASS="code">#define BOOST_NO_MT</SPAN> before any inclusion of this header.  To prevent ODR violations, this should be defined in <STRONG>every</STRONG> translation unit in your project, including any library files.

<P>
<H2>Synopsis</H2>

<PRE CLASS="code">namespace details {
namespace pool {

// Only present if on a Win32 system
class Win32_mutex
{
  private:
    Win32_mutex(const Win32_mutex &amp;);
    void operator=(const Win32_mutex &amp;);

  public:
    Win32_mutex();
    ~Win32_mutex();

    void lock();
    void unlock();
};

// Only present if on a POSIX+pthread system
class pthread_mutex
{
  private:
    pthread_mutex(const pthread_mutex &amp;);
    void operator=(const pthread_mutex &amp;);

  public:
    pthread_mutex();
    ~pthread_mutex();

    void lock();
    void unlock();
};

// Present on all systems
class null_mutex
{
  private:
    null_mutex(const null_mutex &amp;);
    void operator=(const null_mutex &amp;);

  public:
    null_mutex();
    ~null_mutex();

    static void lock();
    static void unlock();
};

// This will be one of the types above
typedef ... default_mutex;

} // namespace pool
} // namespace details</PRE>

<P>
<H2>Semantics</H2>

<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Symbol Table</EM></CAPTION>
<TR><TH>Symbol<TH>Meaning
<TR><TD CLASS="code">Mutex<TD>Any type defined in this header
<TR><TD CLASS="code">t<TD>value of type <SPAN CLASS="code">Mutex</SPAN>
</TABLE>

<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Requirements satisfied by <SPAN CLASS="code">mutex</SPAN></EM></CAPTION>
<TR><TH>Expression<TH>Return Type<TH>Assertion/Note/Pre/Post-Condition
<TR><TD CLASS="code">m.lock()<TD>not used<TD>Locks the mutex
<TR><TD CLASS="code">m.unlock()<TD>not used<TD>Unlocks the mutex
</TABLE>

<P>
Each mutex is always either owned or unowned.  If owned, then it is owned by a particular thread.  To &quot;lock&quot; a mutex means to wait until the mutex is unowned, and then make it owned by the current thread.  To &quot;unlock&quot; a mutex means to release ownership from the current thread (note that the current thread <STRONG>must</STRONG> own the mutex to release that ownership!).  As a special case, the <SPAN CLASS="code">null_mutex</SPAN> never waits.

<P>
<H2>Dependencies</H2>

<P>
May include the system headers <SPAN CLASS="code">&lt;windows.h&gt;</SPAN>, <SPAN CLASS="code">&lt;unistd.h&gt;</SPAN>, and/or <SPAN CLASS="code">&lt;pthread.h&gt;</SPAN>.

<P>
<H2>Future Directions</H2>

<P>
This header will eventually be replaced by a Boost multithreading library.

<P>
<HR>

<P>
Copyright &copy; 2000, 2001 Stephen Cleary (<A HREF="mailto:shammah@voyager.net">shammah@voyager.net</A>)

<P>
This file can be redistributed and/or modified under the terms found in <A HREF="../copyright.html">copyright.html</A>

<P>
This software and its documentation is provided &quot;as is&quot; without express or implied warranty, and with no claim as to its suitability for any purpose.

</BODY>
</HTML>