#include #include #include #include #include #include #include // // gcc -g -Wall -o multithread_quick_window multithread_quick_window.c -lX11 // // test case for a window which only exists briefly causing a X server segfault // static void * worker(void *ignored) { // Open the display Display *dpy = XOpenDisplay(NULL); assert(dpy); // Get some colors int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); while (1) { XSizeHints sh; int t; // Create the window Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, blackColor, blackColor); sh.width = 200; sh.height = 100; sh.x = 0; sh.y = 0; // sh.flags = (rand() % 2 == 1) ? (PPosition | USPosition) : 0; sh.flags = (PPosition | USPosition); XSetWMNormalHints(dpy, w, &sh); // Map the window XMapWindow(dpy, w); XFlush(dpy); t = rand() % 500000; usleep(t); XDestroyWindow(dpy, w); XFlush(dpy); t = rand() % 500000; usleep(t); } return 0; } int main() { int i; for (i = 0; i < 8; i++) { pthread_t thread; pthread_create(&thread, NULL, worker, NULL); } worker(NULL); return 0; }