1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
//
// 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;
}
|