From: Adrian Szyndela Date: Tue, 13 Dec 2016 12:19:55 +0000 (+0100) Subject: test program for crashing with threads X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Fsandbox%2Fadrian.s%2Ftest;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git test program for crashing with threads --- diff --git a/tests/test3.c b/tests/test3.c new file mode 100644 index 00000000..ca6ae03c --- /dev/null +++ b/tests/test3.c @@ -0,0 +1,46 @@ +#include +#include +#include + +int crash_other_thread = 0; +#define CRASHING_THREAD 19 + +gboolean crasher(gpointer data) +{ + *(int*)data = 1; + return TRUE; +} + +void *fun(void *arg) +{ + int threadnum = (int)arg; + if (crash_other_thread && threadnum == CRASHING_THREAD) + crasher(NULL); + else + while (1); + return NULL; +} + +int main(int argc) +{ + GMainLoop *loop = g_main_loop_new(NULL, FALSE); + + crash_other_thread = argc > 1; + + if (!crash_other_thread) + { + GSource *idle_source = g_idle_source_new(); + g_source_set_callback(idle_source, crasher, NULL, NULL); + g_source_attach(idle_source, g_main_context_ref_thread_default()); + } + + pthread_t t; + int i; + + for (i = 0; i <= CRASHING_THREAD; i++) + pthread_create(&t, NULL, fun, (void *)i); + + g_main_loop_run(loop); + + return 0; +}