~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qreadwritelock.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/thread/qreadwritelock_unix.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QReadWriteLock Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QReadWriteLock Class Reference</h1>
 
21
<p>The QReadWriteLock class provides read-write locking. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QReadWriteLock&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<p><b>Note:</b> All the functions in this class are <a href="threads.html#thread-safe">thread-safe</a>.</p>
 
24
<ul>
 
25
<li><a href="qreadwritelock-members.html">List of all members, including inherited members</a></li>
 
26
</ul>
 
27
<a name="public-functions"></a>
 
28
<h3>Public Functions</h3>
 
29
<ul>
 
30
<li><div class="fn"/><b><a href="qreadwritelock.html#QReadWriteLock">QReadWriteLock</a></b> ()</li>
 
31
<li><div class="fn"/><b><a href="qreadwritelock.html#dtor.QReadWriteLock">~QReadWriteLock</a></b> ()</li>
 
32
<li><div class="fn"/>void <b><a href="qreadwritelock.html#lockForRead">lockForRead</a></b> ()</li>
 
33
<li><div class="fn"/>void <b><a href="qreadwritelock.html#lockForWrite">lockForWrite</a></b> ()</li>
 
34
<li><div class="fn"/>bool <b><a href="qreadwritelock.html#tryLockForRead">tryLockForRead</a></b> ()</li>
 
35
<li><div class="fn"/>bool <b><a href="qreadwritelock.html#tryLockForWrite">tryLockForWrite</a></b> ()</li>
 
36
<li><div class="fn"/>void <b><a href="qreadwritelock.html#unlock">unlock</a></b> ()</li>
 
37
</ul>
 
38
<a name="details"></a>
 
39
<hr />
 
40
<h2>Detailed Description</h2>
 
41
<p>The QReadWriteLock class provides read-write locking.</p>
 
42
<p>A read-write lock is a synchronization tool for protecting resources that can be accessed for reading and writing. This type of lock is useful if you want to allow multiple threads to have simultaneous read-only access, but as soon as one thread wants to write to the resource, all other threads must be blocked until the writing is complete.</p>
 
43
<p>In many cases, QReadWriteLock is a direct competitor to <a href="qmutex.html">QMutex</a>. QReadWriteLock is a good choice if there are many concurrent reads and writing occurs infrequently.</p>
 
44
<p>Example:</p>
 
45
<pre>&nbsp;   QReadWriteLock lock;
 
46
 
 
47
    void ReaderThread::run()
 
48
    {
 
49
        ...
 
50
        lock.lockForRead();
 
51
        read_file();
 
52
        lock.unlock();
 
53
        ...
 
54
    }
 
55
 
 
56
    void WriterThread::run()
 
57
    {
 
58
        ...
 
59
        lock.lockForWrite();
 
60
        write_file();
 
61
        lock.unlock();
 
62
        ...
 
63
    }</pre>
 
64
<p>To ensure that writers aren't blocked forever by readers, readers attempting to obtain a lock will not succeed if there is a blocked writer waiting for access, even if the lock is currently only accessed by other readers. Also, if the lock is accessed by a writer and another writer comes in, that writer will have priority over any readers that might also be waiting.</p>
 
65
<p>See also <a href="qreadlocker.html">QReadLocker</a>, <a href="qwritelocker.html">QWriteLocker</a>, <a href="qmutex.html">QMutex</a>, and <a href="qsemaphore.html">QSemaphore</a>.</p>
 
66
<hr />
 
67
<h2>Member Function Documentation</h2>
 
68
<h3 class="fn"><a name="QReadWriteLock"></a>QReadWriteLock::QReadWriteLock ()</h3>
 
69
<p>Constructs a <a href="qreadwritelock.html">QReadWriteLock</a> object.</p>
 
70
<p>See also <a href="qreadwritelock.html#lockForRead">lockForRead</a>() and <a href="qreadwritelock.html#lockForWrite">lockForWrite</a>().</p>
 
71
<h3 class="fn"><a name="dtor.QReadWriteLock"></a>QReadWriteLock::~QReadWriteLock ()</h3>
 
72
<p>Destroys the <a href="qreadwritelock.html">QReadWriteLock</a> object.</p>
 
73
<p><b>Warning:</b> Destroying a read-write lock that is in use may result in undefined behavior.</p>
 
74
<h3 class="fn"><a name="lockForRead"></a>void QReadWriteLock::lockForRead ()</h3>
 
75
<p>Locks the lock for reading. This function will block the current thread if another thread has locked for writing.</p>
 
76
<p>See also <a href="qreadwritelock.html#unlock">unlock</a>(), <a href="qreadwritelock.html#lockForWrite">lockForWrite</a>(), and <a href="qreadwritelock.html#tryLockForRead">tryLockForRead</a>().</p>
 
77
<h3 class="fn"><a name="lockForWrite"></a>void QReadWriteLock::lockForWrite ()</h3>
 
78
<p>Locks the lock for writing. This function will block the current thread if any thread has locked for reading or writing.</p>
 
79
<p>See also <a href="qreadwritelock.html#unlock">unlock</a>(), <a href="qreadwritelock.html#lockForRead">lockForRead</a>(), and <a href="qreadwritelock.html#tryLockForWrite">tryLockForWrite</a>().</p>
 
80
<h3 class="fn"><a name="tryLockForRead"></a>bool QReadWriteLock::tryLockForRead ()</h3>
 
81
<p>Attempts to lock for reading. If the lock was obtained, this function returns true, otherwise it returns false instead of waiting for the lock to become available, i.e. it does not block.</p>
 
82
<p>The lock attempt will fail if another thread has locked for writing.</p>
 
83
<p>If the lock was obtained, the lock must be unlocked with <a href="qreadwritelock.html#unlock">unlock</a>() before another thread can successfully lock it.</p>
 
84
<p>See also <a href="qreadwritelock.html#unlock">unlock</a>() and <a href="qreadwritelock.html#lockForRead">lockForRead</a>().</p>
 
85
<h3 class="fn"><a name="tryLockForWrite"></a>bool QReadWriteLock::tryLockForWrite ()</h3>
 
86
<p>Attempts to lock for writing. If the lock was obtained, this function returns true; otherwise, it returns false immediately.</p>
 
87
<p>The lock attempt will fail if any thread has locked for reading or writing.</p>
 
88
<p>If the lock was obtained, the lock must be unlocked with <a href="qreadwritelock.html#unlock">unlock</a>() before another thread can successfully lock it.</p>
 
89
<p>See also <a href="qreadwritelock.html#unlock">unlock</a>() and <a href="qreadwritelock.html#lockForWrite">lockForWrite</a>().</p>
 
90
<h3 class="fn"><a name="unlock"></a>void QReadWriteLock::unlock ()</h3>
 
91
<p>Unlocks the lock.</p>
 
92
<p>Attempting to unlock a lock that is not locked is an error, and will result in program termination.</p>
 
93
<p>See also <a href="qreadwritelock.html#lockForRead">lockForRead</a>(), <a href="qreadwritelock.html#lockForWrite">lockForWrite</a>(), <a href="qreadwritelock.html#tryLockForRead">tryLockForRead</a>(), and <a href="qreadwritelock.html#tryLockForWrite">tryLockForWrite</a>().</p>
 
94
<p /><address><hr /><div align="center">
 
95
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
96
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
97
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
98
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
99
</tr></table></div></address></body>
 
100
</html>