diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-07-15 21:20:14 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-07-15 21:20:14 +0200 |
commit | 82e9ac4163b46b59e121194f84ac370818482923 (patch) | |
tree | b52adf8f5b2bafe7904f563c33ec23f46cb7c87c /content/20210515-pthread_cancel-noexcept | |
parent | 617d73fc9eff5b08a80b873fd97f66caa7e80fc9 (diff) | |
download | blog-82e9ac4163b46b59e121194f84ac370818482923.tar.gz blog-82e9ac4163b46b59e121194f84ac370818482923.zip |
use proper date fmt in content file names that zola can automatically can derive the date
Diffstat (limited to 'content/20210515-pthread_cancel-noexcept')
-rw-r--r-- | content/20210515-pthread_cancel-noexcept/thread.cc | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/content/20210515-pthread_cancel-noexcept/thread.cc b/content/20210515-pthread_cancel-noexcept/thread.cc deleted file mode 100644 index 73370be..0000000 --- a/content/20210515-pthread_cancel-noexcept/thread.cc +++ /dev/null @@ -1,40 +0,0 @@ -// file : thread.cc -// compile: g++ thread.cc -o thread -lpthread - -#include <atomic> - -#include <pthread.h> -#include <unistd.h> - -struct S { - ~S() { - const char msg[] = "cancellation-point\n"; - // write() -> pthread cancellation point. - write(STDOUT_FILENO, msg, sizeof(msg)); - } -}; - -std::atomic<bool> gReleaseThread{false}; - -void* threadFn(void*) { - while (!gReleaseThread) {} - - // Hit cancellation point in destructor which - // is implicitly `noexcept`. - S s; - - return nullptr; -} - -int main() { - pthread_t t; - pthread_create(&t, nullptr /* attr */, threadFn, nullptr /* arg */); - - // Cancel thread and release it to hit the cancellation point. - pthread_cancel(t); - gReleaseThread = true; - - pthread_join(t, nullptr /* retval */); - - return 0; -} |