Delve into programming the Windows operating system through the Windows API in with C++. Use the power of the Windows API to working with processes, threads, jobs, memory, I/O and more. The book covers current Windows 10 versions, allowing you to get the most of what Windows has to offer to developers in terms of productivity, performance and scalability.
========================================================================= Problém (R1): Kapitola 7, sekce Condition Variables, demo The Queue Demo Application. Race condition a UB (undefined behavior): 1) Spustí se Consumer thread. 2) Proměnná data je přidána do kolekce - m_ConsumerThreads.push_back(std::move(data)); 3) Consumer thread si hned vyzvedne data (auto& data = m_ConsumerThreads[index];). Race - aplikace asi necrashuje, protože bylo voláno m_ConsumerThreads.reserve(consumers); - ale sáhne si na neinicializovaná data v m_ConsumerThreads a může se updatova jiný objekt. Pokud Consumer thread naběhne až poté, co jsou data přidána, vše je OK.
m_ConsumerThreads.clear(); m_ConsumerThreads.reserve(consumers); for (int i = 0; i < consumers; i++) { ConsumerThreadData data; data.hThread.reset(::CreateThread(nullptr, 0, [](auto p) { return m_pThis->ConsumerThread(PtrToLong(p)); }, LongToPtr(i), 0, nullptr)); if (!data.hThread) { abort = true; break; } m_ConsumerThreads.push_back(std::move(data)); } if (abort) { ::SetEvent(m_hAbortEvent.get()); return; }
DWORD CMainDlg::ConsumerThread(int index) { auto& data = m_ConsumerThreads[index]; auto tick = ::GetTickCount64();
More practical than "Windows Internals" with a lot of code snippets, interesting applications and introduction of tools that helps understand Windows under the hood.