-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added thread notifier
- Loading branch information
Showing
10 changed files
with
134 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# examples/examples.cmake | ||
set(MAIN_SRC ${Q_SOURCE_DIR}/examples/spsc_main.cpp) | ||
add_executable(example_spsc ${MAIN_SRC}) | ||
set(SPSC_EXAMPLE_SRC ${Q_SOURCE_DIR}/examples/spsc_main.cpp) | ||
add_executable(example_spsc ${SPSC_EXAMPLE_SRC}) | ||
target_link_libraries(example_spsc ${Q_LIBRARY}) | ||
|
||
set(NOTIFY_EXAMPLE_SRC ${Q_SOURCE_DIR}/examples/thread_notify_main.cpp) | ||
add_executable(example_thread_notify ${NOTIFY_EXAMPLE_SRC}) | ||
target_link_libraries(example_thread_notify ${Q_LIBRARY}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <chrono> | ||
#include <iostream> | ||
#include <thread> | ||
#include "q/thread_exit_notifier.hpp" | ||
|
||
void coutThreadExit(std::thread::id id) { | ||
std::cout << "Thread " << id << " has exited." << std::endl; | ||
} | ||
|
||
void threadRun() { | ||
thread_local ThreadExitNotifier notifier(coutThreadExit); | ||
for (int i = 0; i < 5; ++i) { | ||
std::cout << "Thread " << std::this_thread::get_id() << " is running iteration " << i << std::endl; | ||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
} | ||
} | ||
|
||
int main() { | ||
{ | ||
std::thread thread1(threadRun); | ||
std::thread thread2(threadRun); | ||
|
||
thread1.join(); | ||
thread2.join(); | ||
} | ||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.