mirror of
https://github.com/boostorg/pool.git
synced 2026-01-23 17:52:15 +00:00
129 lines
3.7 KiB
HTML
129 lines
3.7 KiB
HTML
<!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 &);
|
|
void operator=(const Win32_mutex &);
|
|
|
|
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 &);
|
|
void operator=(const pthread_mutex &);
|
|
|
|
public:
|
|
pthread_mutex();
|
|
~pthread_mutex();
|
|
|
|
void lock();
|
|
void unlock();
|
|
};
|
|
|
|
// Present on all systems
|
|
class null_mutex
|
|
{
|
|
private:
|
|
null_mutex(const null_mutex &);
|
|
void operator=(const null_mutex &);
|
|
|
|
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 "lock" a mutex means to wait until the mutex is unowned, and then make it owned by the current thread. To "unlock" 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"><windows.h></SPAN>, <SPAN CLASS="code"><unistd.h></SPAN>, and/or <SPAN CLASS="code"><pthread.h></SPAN>.
|
|
|
|
<P>
|
|
<H2>Future Directions</H2>
|
|
|
|
<P>
|
|
This header will eventually be replaced by a Boost multithreading library.
|
|
|
|
<P>
|
|
<HR>
|
|
|
|
<P>
|
|
Copyright © 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 "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
|
|
|
|
</BODY>
|
|
</HTML> |