#include #include #include #include #include #include #define OUT(x) fprintf(stderr, "%s\n", x) class xDisplay { public: xDisplay() { OUT("calling XInitThreads"); XInitThreads(); OUT("opening display"); _disp = XOpenDisplay(NULL); XSetIOErrorHandler(iohandler); //XSetErrorHandler(handler); } ~xDisplay() { if (_disp != NULL) { OUT("closing display"); XCloseDisplay(_disp); _disp = NULL; } } operator Display* () { return _disp; } private: static int iohandler(Display* disp) { OUT("IO error"); getc(stdin); return 0; } static int handler(Display* disp, XErrorEvent* err) { OUT("error"); return 0; } Display* _disp; }; // Display xDisplay display; void* tproc(void* param) { XEvent ev; OUT("entering tproc"); while (1) { XNextEvent(display, &ev); } return 0; } void create_thread() { pthread_t pt; pthread_create(&pt, NULL, tproc, NULL); } Colormap create_cmap() { Colormap cmap = 0; XVisualInfo info; XMatchVisualInfo(display, DefaultScreen((Display*)display), 8, PseudoColor, &info); cmap = XCreateColormap(display, DefaultRootWindow((Display*)display), info.visual, AllocNone); return cmap; } void alloc_colors() { Colormap cmap = create_cmap(); unsigned long pixels[1024]; unsigned int npixels = 250; OUT("looping XAllocColorCells"); while (1) { fprintf(stderr, "colors %d\n", npixels); if (XAllocColorCells(display, cmap, False, NULL, 0, pixels, npixels) == 0) { OUT("XAllocColorCells failed"); break; } XFreeColors(display, cmap, pixels, npixels, 0); npixels ++; } OUT("done looping XAllocColorCells"); XFreeColormap(display, cmap); } int main() { int count = 0; //XSynchronize(display, True); create_thread(); alloc_colors(); }