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_qwaitcondition_unix.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 <QWaitCondition>
5#include <QMutex>
6
8void sleep(int seconds);
9
10
12{
13 QMutex mutex;
14 QWaitCondition keyPressed;
15 int count;
16
17 //! [0]
18 forever {
19 mutex.lock();
20 keyPressed.wait(&mutex);
21 do_something();
22 mutex.unlock();
23 }
24 //! [0]
25
26
27 //! [1]
28 forever {
29 getchar();
30 keyPressed.wakeAll();
31 }
32 //! [1]
33
34
35 //! [2]
36 forever {
37 mutex.lock();
38 keyPressed.wait(&mutex);
39 ++count;
40 mutex.unlock();
41
42 do_something();
43
44 mutex.lock();
45 --count;
46 mutex.unlock();
47 }
48 //! [2]
49
50
51 //! [3]
52 forever {
53 getchar();
54
55 mutex.lock();
56 // Sleep until there are no busy worker threads
57 while (count > 0) {
58 mutex.unlock();
59 sleep(1);
60 mutex.lock();
61 }
62 keyPressed.wakeAll();
63 mutex.unlock();
64 }
65 //! [3]
66}
bool examples()
[3]
void do_something()
void sleep(int seconds)