diff options
author | comex | 2015-01-21 18:24:08 -0500 |
---|---|---|
committer | comex | 2015-01-21 18:24:08 -0500 |
commit | 2795a1a5b34bffc350f9366fcf05a6165067eafa (patch) | |
tree | 23d2a31654b4306637fc56796d82962abec3a337 /test | |
parent | add substitute_strerror (diff) | |
download | substitute-2795a1a5b34bffc350f9366fcf05a6165067eafa.tar.gz |
stopping other threads.
Diffstat (limited to 'test')
-rw-r--r-- | test/test-stop-threads.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/test-stop-threads.c b/test/test-stop-threads.c new file mode 100644 index 0000000..be0787d --- /dev/null +++ b/test/test-stop-threads.c @@ -0,0 +1,34 @@ +#include "substitute-internal.h" +#include <stdio.h> +#include <unistd.h> +#include <pthread.h> +#include <assert.h> +static void *some_thread(void *ip) { + long i = (long) ip; + while (1) { + printf("Hello from %ld\n", i); + sleep(1); + } +} +static void replacement() { + printf("Bye\n"); + pthread_exit(NULL); +} +static uintptr_t patch_callback(void *ctx, UNUSED uintptr_t pc) { + assert(!ctx); + return (uintptr_t) replacement; +} + +int main() { + pthread_t pts[10]; + for (long i = 0; i < 10; i++) + pthread_create(&pts[i], NULL, some_thread, (void *) i); + sleep(1); + void *stop_token; + assert(!stop_other_threads(&stop_token)); + assert(!apply_pc_patch_callback(stop_token, patch_callback, NULL)); + assert(!resume_other_threads(stop_token)); + void *out; + for (long i = 0; i < 10; i++) + assert(!pthread_join(pts[i], &out)); +} |