/*
gcc -Wall -O2 -g -std=gnu99 -o crash crash.c \
        $(pkg-config glib-2.0 --cflags --libs)
*/

#include <sys/wait.h>
#include <unistd.h>
#include <glib.h>

#define NUM_THREADS 10

static void *worker(void *data)
{
    g_get_language_names();
    return NULL;
}

int main(int argc, char **argv)
{
    // repeatedly fork children until one of them crashes
    while (1) {
        if (fork()) {
            // parent
            int ret;
            wait(&ret);
            if (ret)
                return 0;

        } else {
            // child: start multiple threads
            for (int i = 0; i < NUM_THREADS; i++) {
                GThread *thread = g_thread_new(NULL, worker, NULL);
                g_thread_unref(thread);
            }
            return 0;
        }
    }
}
