October 2018
Beginner
794 pages
19h 23m
English
A simple code example demonstrating thread-cancelation follows; we have the main thread create two worker threads (think of them as thread A and thread B) and then have the main thread cancel thread A. In parallel, we deliberately have thread A disable cancelation (by setting the cancelation state to disabled), do some bogus work (we call our trusty DELAY_LOOP macro to simulate work), then re-enable cancelation. The cancelation request takes effect at the next cancelation point (as, of course, the type defaults to deferred), which, here, is simply the sleep(3) API.
The code demonstrating thread cancelation (ch16/cancelit.c) follows.
Read now
Unlock full access