Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_thread_qreadwritelock.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QReadWriteLock>
5#include <QByteArray>
6
8{
9public:
10 void run();
11};
12
14{
15public:
16 void run();
17};
18
19void read_file();
21
22//! [lock]
24
25//! [lock]
26
27//! [0]
29{
30 //...
31 lock.lockForRead();
33 lock.unlock();
34 //...
35}
36
38{
39 //...
40 lock.lockForWrite();
42 lock.unlock();
43 //...
44}
45//! [0]
46
48
49//! [1]
51{
52 QReadLocker locker(&lock);
53 //...
54 return data;
55}
56//! [1]
57
58namespace duplicate_examples
59{
62
63 //! [2]
65 {
66 lock.lockForRead();
67 //...
68 lock.unlock();
69 return data;
70 }
71 //! [2]
72
73
74 //! [3]
75 void writeData(const QByteArray &data)
76 {
77 QWriteLocker locker(&lock);
78 //...
79 }
80 //! [3]
81}
82
83//! [4]
84void writeData(const QByteArray &data)
85{
86 lock.lockForWrite();
87 //...
88 lock.unlock();
89}
90//! [4]
void writeData(const QByteArray &data)
[2]
void read_file()
QReadWriteLock lock
[lock]
void writeData(const QByteArray &data)
[4]
void write_file()
QByteArray readData()
[1]