MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / testMutex

Method testMutex

Tests/Libraries/Threading/ThreadingTest.cpp:115–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115void SC::ThreadingTest::testMutex()
116{
117 //! [mutexSnippet]
118 Mutex mutex;
119 int globalVariable = 0;
120 Thread thread1;
121 auto thread1Func = [&](Thread& thread)
122 {
123 thread.setThreadName(SC_NATIVE_STR("Thread1"));
124 mutex.lock();
125 globalVariable++;
126 mutex.unlock();
127 };
128 SC_TEST_EXPECT(thread1.start(thread1Func));
129
130 Thread thread2;
131 auto thread2Func = [&](Thread& thread)
132 {
133 thread.setThreadName(SC_NATIVE_STR("Signaling2"));
134 mutex.lock();
135 globalVariable++;
136 mutex.unlock();
137 };
138 SC_TEST_EXPECT(thread2.start(thread2Func));
139 SC_TEST_EXPECT(thread1.join());
140 SC_TEST_EXPECT(thread2.join());
141 SC_TEST_EXPECT(globalVariable == 2);
142 //! [mutexSnippet]
143}
144
145void SC::ThreadingTest::testRWLock()
146{

Callers

nothing calls this directly

Calls 5

setThreadNameMethod · 0.45
lockMethod · 0.45
unlockMethod · 0.45
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected