Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glthreads.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * Copyright (C) 2000 Brian Paul All Rights Reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included
  12. * in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  18. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. /*
  22. * This program tests GLX thread safety.
  23. * Command line options:
  24. * -p Open a display connection for each thread
  25. * -l Enable application-side locking
  26. * -n <num threads> Number of threads to create (default is 2)
  27. * -display <display name> Specify X display (default is :0.0)
  28. * -t Use texture mapping
  29. *
  30. * Brian Paul 20 July 2000
  31. */
  32. /*
  33. * Notes:
  34. * - Each thread gets its own GLX context.
  35. *
  36. * - The GLX contexts share texture objects.
  37. *
  38. * - When 't' is pressed to update the texture image, the window/thread which
  39. * has input focus is signalled to change the texture. The other threads
  40. * should see the updated texture the next time they call glBindTexture.
  41. */
  42. #if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */
  43. #include <assert.h>
  44. #include <GL/gl.h>
  45. #include <GL/glx.h>
  46. #include <math.h>
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include <unistd.h>
  51. #include <pthread.h>
  52. /*
  53. * Each window/thread/context:
  54. */
  55. struct winthread {
  56. Display *Dpy;
  57. int Index;
  58. pthread_t Thread;
  59. Window Win;
  60. GLXContext Context;
  61. float Angle;
  62. int WinWidth, WinHeight;
  63. GLboolean NewSize;
  64. GLboolean Initialized;
  65. GLboolean MakeNewTexture;
  66. };
  67. #define MAX_WINTHREADS 100
  68. static struct winthread WinThreads[MAX_WINTHREADS];
  69. static int NumWinThreads = 0;
  70. static volatile GLboolean ExitFlag = GL_FALSE;
  71. static GLboolean MultiDisplays = 0;
  72. static GLboolean Locking = 0;
  73. static GLboolean Texture = GL_FALSE;
  74. static GLuint TexObj = 12;
  75. static GLboolean Animate = GL_TRUE;
  76. static pthread_mutex_t Mutex;
  77. static pthread_cond_t CondVar;
  78. static pthread_mutex_t CondMutex;
  79. static void
  80. Error(const char *msg)
  81. {
  82. fprintf(stderr, "Error: %s\n", msg);
  83. exit(1);
  84. }
  85. static void
  86. signal_redraw(void)
  87. {
  88. pthread_mutex_lock(&CondMutex);
  89. pthread_cond_broadcast(&CondVar);
  90. pthread_mutex_unlock(&CondMutex);
  91. }
  92. static void
  93. MakeNewTexture(struct winthread *wt)
  94. {
  95. #define TEX_SIZE 128
  96. static float step = 0.0;
  97. GLfloat image[TEX_SIZE][TEX_SIZE][4];
  98. GLint width;
  99. int i, j;
  100. for (j = 0; j < TEX_SIZE; j++) {
  101. for (i = 0; i < TEX_SIZE; i++) {
  102. float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE;
  103. float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE;
  104. float r = dt * dt + ds * ds + step;
  105. image[j][i][0] =
  106. image[j][i][1] =
  107. image[j][i][2] = 0.75 + 0.25 * cos(r);
  108. image[j][i][3] = 1.0;
  109. }
  110. }
  111. step += 0.5;
  112. glBindTexture(GL_TEXTURE_2D, TexObj);
  113. glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
  114. if (width) {
  115. assert(width == TEX_SIZE);
  116. /* sub-tex replace */
  117. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE,
  118. GL_RGBA, GL_FLOAT, image);
  119. }
  120. else {
  121. /* create new */
  122. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  123. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  124. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0,
  125. GL_RGBA, GL_FLOAT, image);
  126. }
  127. }
  128. /* draw a colored cube */
  129. static void
  130. draw_object(void)
  131. {
  132. glPushMatrix();
  133. glScalef(0.75, 0.75, 0.75);
  134. glColor3f(1, 0, 0);
  135. if (Texture) {
  136. glBindTexture(GL_TEXTURE_2D, TexObj);
  137. glEnable(GL_TEXTURE_2D);
  138. }
  139. else {
  140. glDisable(GL_TEXTURE_2D);
  141. }
  142. glBegin(GL_QUADS);
  143. /* -X */
  144. glColor3f(0, 1, 1);
  145. glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  146. glTexCoord2f(1, 0); glVertex3f(-1, 1, -1);
  147. glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
  148. glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
  149. /* +X */
  150. glColor3f(1, 0, 0);
  151. glTexCoord2f(0, 0); glVertex3f(1, -1, -1);
  152. glTexCoord2f(1, 0); glVertex3f(1, 1, -1);
  153. glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
  154. glTexCoord2f(0, 1); glVertex3f(1, -1, 1);
  155. /* -Y */
  156. glColor3f(1, 0, 1);
  157. glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  158. glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
  159. glTexCoord2f(1, 1); glVertex3f( 1, -1, 1);
  160. glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
  161. /* +Y */
  162. glColor3f(0, 1, 0);
  163. glTexCoord2f(0, 0); glVertex3f(-1, 1, -1);
  164. glTexCoord2f(1, 0); glVertex3f( 1, 1, -1);
  165. glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
  166. glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
  167. /* -Z */
  168. glColor3f(1, 1, 0);
  169. glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
  170. glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
  171. glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
  172. glTexCoord2f(0, 1); glVertex3f(-1, 1, -1);
  173. /* +Y */
  174. glColor3f(0, 0, 1);
  175. glTexCoord2f(0, 0); glVertex3f(-1, -1, 1);
  176. glTexCoord2f(1, 0); glVertex3f( 1, -1, 1);
  177. glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
  178. glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
  179. glEnd();
  180. glPopMatrix();
  181. }
  182. /* signal resize of given window */
  183. static void
  184. resize(struct winthread *wt, int w, int h)
  185. {
  186. wt->NewSize = GL_TRUE;
  187. wt->WinWidth = w;
  188. wt->WinHeight = h;
  189. if (!Animate)
  190. signal_redraw();
  191. }
  192. /*
  193. * We have an instance of this for each thread.
  194. */
  195. static void
  196. draw_loop(struct winthread *wt)
  197. {
  198. while (!ExitFlag) {
  199. if (Locking)
  200. pthread_mutex_lock(&Mutex);
  201. glXMakeCurrent(wt->Dpy, wt->Win, wt->Context);
  202. if (!wt->Initialized) {
  203. printf("glthreads: %d: GL_RENDERER = %s\n", wt->Index,
  204. (char *) glGetString(GL_RENDERER));
  205. if (Texture /*&& wt->Index == 0*/) {
  206. MakeNewTexture(wt);
  207. }
  208. wt->Initialized = GL_TRUE;
  209. }
  210. if (Locking)
  211. pthread_mutex_unlock(&Mutex);
  212. glEnable(GL_DEPTH_TEST);
  213. if (wt->NewSize) {
  214. GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight;
  215. glViewport(0, 0, wt->WinWidth, wt->WinHeight);
  216. glMatrixMode(GL_PROJECTION);
  217. glLoadIdentity();
  218. glFrustum(-w, w, -1.0, 1.0, 1.5, 10);
  219. glMatrixMode(GL_MODELVIEW);
  220. glLoadIdentity();
  221. glTranslatef(0, 0, -2.5);
  222. wt->NewSize = GL_FALSE;
  223. }
  224. if (wt->MakeNewTexture) {
  225. MakeNewTexture(wt);
  226. wt->MakeNewTexture = GL_FALSE;
  227. }
  228. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  229. glPushMatrix();
  230. glRotatef(wt->Angle, 0, 1, 0);
  231. glRotatef(wt->Angle, 1, 0, 0);
  232. glScalef(0.7, 0.7, 0.7);
  233. draw_object();
  234. glPopMatrix();
  235. if (Locking)
  236. pthread_mutex_lock(&Mutex);
  237. glXSwapBuffers(wt->Dpy, wt->Win);
  238. if (Locking)
  239. pthread_mutex_unlock(&Mutex);
  240. if (Animate) {
  241. usleep(5000);
  242. }
  243. else {
  244. /* wait for signal to draw */
  245. pthread_mutex_lock(&CondMutex);
  246. pthread_cond_wait(&CondVar, &CondMutex);
  247. pthread_mutex_unlock(&CondMutex);
  248. }
  249. wt->Angle += 1.0;
  250. }
  251. }
  252. static void
  253. keypress(XEvent *event, struct winthread *wt)
  254. {
  255. char buf[100];
  256. KeySym keySym;
  257. XComposeStatus stat;
  258. XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat);
  259. switch (keySym) {
  260. case XK_Escape:
  261. /* tell all threads to exit */
  262. if (!Animate) {
  263. signal_redraw();
  264. }
  265. ExitFlag = GL_TRUE;
  266. /*printf("exit draw_loop %d\n", wt->Index);*/
  267. return;
  268. case XK_t:
  269. case XK_T:
  270. if (Texture) {
  271. wt->MakeNewTexture = GL_TRUE;
  272. if (!Animate)
  273. signal_redraw();
  274. }
  275. break;
  276. case XK_a:
  277. case XK_A:
  278. Animate = !Animate;
  279. if (Animate) /* yes, prev Animate state! */
  280. signal_redraw();
  281. break;
  282. case XK_s:
  283. case XK_S:
  284. if (!Animate)
  285. signal_redraw();
  286. break;
  287. default:
  288. ; /* nop */
  289. }
  290. }
  291. /*
  292. * The main process thread runs this loop.
  293. * Single display connection for all threads.
  294. */
  295. static void
  296. event_loop(Display *dpy)
  297. {
  298. XEvent event;
  299. int i;
  300. assert(!MultiDisplays);
  301. while (!ExitFlag) {
  302. if (Locking) {
  303. while (1) {
  304. int k;
  305. pthread_mutex_lock(&Mutex);
  306. k = XPending(dpy);
  307. if (k) {
  308. XNextEvent(dpy, &event);
  309. pthread_mutex_unlock(&Mutex);
  310. break;
  311. }
  312. pthread_mutex_unlock(&Mutex);
  313. usleep(5000);
  314. }
  315. }
  316. else {
  317. XNextEvent(dpy, &event);
  318. }
  319. switch (event.type) {
  320. case ConfigureNotify:
  321. /* Find winthread for this event's window */
  322. for (i = 0; i < NumWinThreads; i++) {
  323. struct winthread *wt = &WinThreads[i];
  324. if (event.xconfigure.window == wt->Win) {
  325. resize(wt, event.xconfigure.width,
  326. event.xconfigure.height);
  327. break;
  328. }
  329. }
  330. break;
  331. case KeyPress:
  332. for (i = 0; i < NumWinThreads; i++) {
  333. struct winthread *wt = &WinThreads[i];
  334. if (event.xkey.window == wt->Win) {
  335. keypress(&event, wt);
  336. break;
  337. }
  338. }
  339. break;
  340. default:
  341. /*no-op*/ ;
  342. }
  343. }
  344. }
  345. /*
  346. * Separate display connection for each thread.
  347. */
  348. static void
  349. event_loop_multi(void)
  350. {
  351. XEvent event;
  352. int w = 0;
  353. assert(MultiDisplays);
  354. while (!ExitFlag) {
  355. struct winthread *wt = &WinThreads[w];
  356. if (XPending(wt->Dpy)) {
  357. XNextEvent(wt->Dpy, &event);
  358. switch (event.type) {
  359. case ConfigureNotify:
  360. resize(wt, event.xconfigure.width, event.xconfigure.height);
  361. break;
  362. case KeyPress:
  363. keypress(&event, wt);
  364. break;
  365. default:
  366. ; /* nop */
  367. }
  368. }
  369. w = (w + 1) % NumWinThreads;
  370. usleep(5000);
  371. }
  372. }
  373. /*
  374. * we'll call this once for each thread, before the threads are created.
  375. */
  376. static void
  377. create_window(struct winthread *wt, GLXContext shareCtx)
  378. {
  379. Window win;
  380. GLXContext ctx;
  381. int attrib[] = { GLX_RGBA,
  382. GLX_RED_SIZE, 1,
  383. GLX_GREEN_SIZE, 1,
  384. GLX_BLUE_SIZE, 1,
  385. GLX_DEPTH_SIZE, 1,
  386. GLX_DOUBLEBUFFER,
  387. None };
  388. int scrnum;
  389. XSetWindowAttributes attr;
  390. unsigned long mask;
  391. Window root;
  392. XVisualInfo *visinfo;
  393. int width = 160, height = 160;
  394. int xpos = (wt->Index % 8) * (width + 10);
  395. int ypos = (wt->Index / 8) * (width + 20);
  396. scrnum = DefaultScreen(wt->Dpy);
  397. root = RootWindow(wt->Dpy, scrnum);
  398. visinfo = glXChooseVisual(wt->Dpy, scrnum, attrib);
  399. if (!visinfo) {
  400. Error("Unable to find RGB, Z, double-buffered visual");
  401. }
  402. /* window attributes */
  403. attr.background_pixel = 0;
  404. attr.border_pixel = 0;
  405. attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone);
  406. attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  407. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  408. win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height,
  409. 0, visinfo->depth, InputOutput,
  410. visinfo->visual, mask, &attr);
  411. if (!win) {
  412. Error("Couldn't create window");
  413. }
  414. {
  415. XSizeHints sizehints;
  416. sizehints.x = xpos;
  417. sizehints.y = ypos;
  418. sizehints.width = width;
  419. sizehints.height = height;
  420. sizehints.flags = USSize | USPosition;
  421. XSetNormalHints(wt->Dpy, win, &sizehints);
  422. XSetStandardProperties(wt->Dpy, win, "glthreads", "glthreads",
  423. None, (char **)NULL, 0, &sizehints);
  424. }
  425. ctx = glXCreateContext(wt->Dpy, visinfo, shareCtx, True);
  426. if (!ctx) {
  427. Error("Couldn't create GLX context");
  428. }
  429. XMapWindow(wt->Dpy, win);
  430. XSync(wt->Dpy, 0);
  431. /* save the info for this window/context */
  432. wt->Win = win;
  433. wt->Context = ctx;
  434. wt->Angle = 0.0;
  435. wt->WinWidth = width;
  436. wt->WinHeight = height;
  437. wt->NewSize = GL_TRUE;
  438. }
  439. /*
  440. * Called by pthread_create()
  441. */
  442. static void *
  443. thread_function(void *p)
  444. {
  445. struct winthread *wt = (struct winthread *) p;
  446. draw_loop(wt);
  447. return NULL;
  448. }
  449. /*
  450. * called before exit to wait for all threads to finish
  451. */
  452. static void
  453. clean_up(void)
  454. {
  455. int i;
  456. /* wait for threads to finish */
  457. for (i = 0; i < NumWinThreads; i++) {
  458. pthread_join(WinThreads[i].Thread, NULL);
  459. }
  460. for (i = 0; i < NumWinThreads; i++) {
  461. glXDestroyContext(WinThreads[i].Dpy, WinThreads[i].Context);
  462. XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win);
  463. }
  464. }
  465. static void
  466. usage(void)
  467. {
  468. printf("glthreads: test of GL thread safety (any key = exit)\n");
  469. printf("Usage:\n");
  470. printf(" glthreads [options]\n");
  471. printf("Options:\n");
  472. printf(" -display DISPLAYNAME Specify display string\n");
  473. printf(" -n NUMTHREADS Number of threads to create\n");
  474. printf(" -p Use a separate display connection for each thread\n");
  475. printf(" -l Use application-side locking\n");
  476. printf(" -t Enable texturing\n");
  477. printf("Keyboard:\n");
  478. printf(" Esc Exit\n");
  479. printf(" t Change texture image (requires -t option)\n");
  480. printf(" a Toggle animation\n");
  481. printf(" s Step rotation (when not animating)\n");
  482. }
  483. int
  484. main(int argc, char *argv[])
  485. {
  486. char *displayName = ":0.0";
  487. int numThreads = 2;
  488. Display *dpy = NULL;
  489. int i;
  490. Status threadStat;
  491. if (argc == 1) {
  492. usage();
  493. }
  494. else {
  495. int i;
  496. for (i = 1; i < argc; i++) {
  497. if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
  498. displayName = argv[i + 1];
  499. i++;
  500. }
  501. else if (strcmp(argv[i], "-p") == 0) {
  502. MultiDisplays = 1;
  503. }
  504. else if (strcmp(argv[i], "-l") == 0) {
  505. Locking = 1;
  506. }
  507. else if (strcmp(argv[i], "-t") == 0) {
  508. Texture = 1;
  509. }
  510. else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) {
  511. numThreads = atoi(argv[i + 1]);
  512. if (numThreads < 1)
  513. numThreads = 1;
  514. else if (numThreads > MAX_WINTHREADS)
  515. numThreads = MAX_WINTHREADS;
  516. i++;
  517. }
  518. else {
  519. usage();
  520. exit(1);
  521. }
  522. }
  523. }
  524. if (Locking)
  525. printf("glthreads: Using explicit locks around Xlib calls.\n");
  526. else
  527. printf("glthreads: No explict locking.\n");
  528. if (MultiDisplays)
  529. printf("glthreads: Per-thread display connections.\n");
  530. else
  531. printf("glthreads: Single display connection.\n");
  532. /*
  533. * VERY IMPORTANT: call XInitThreads() before any other Xlib functions.
  534. */
  535. if (!MultiDisplays) {
  536. if (!Locking) {
  537. threadStat = XInitThreads();
  538. if (threadStat) {
  539. printf("XInitThreads() returned %d (success)\n", (int) threadStat);
  540. }
  541. else {
  542. printf("XInitThreads() returned 0 (failure- this program may fail)\n");
  543. }
  544. }
  545. dpy = XOpenDisplay(displayName);
  546. if (!dpy) {
  547. fprintf(stderr, "Unable to open display %s\n", XDisplayName(displayName));
  548. return -1;
  549. }
  550. }
  551. pthread_mutex_init(&Mutex, NULL);
  552. pthread_mutex_init(&CondMutex, NULL);
  553. pthread_cond_init(&CondVar, NULL);
  554. printf("glthreads: creating windows\n");
  555. NumWinThreads = numThreads;
  556. /* Create the GLX windows and contexts */
  557. for (i = 0; i < numThreads; i++) {
  558. GLXContext share;
  559. if (MultiDisplays) {
  560. WinThreads[i].Dpy = XOpenDisplay(displayName);
  561. assert(WinThreads[i].Dpy);
  562. }
  563. else {
  564. WinThreads[i].Dpy = dpy;
  565. }
  566. WinThreads[i].Index = i;
  567. WinThreads[i].Initialized = GL_FALSE;
  568. share = (Texture && i > 0) ? WinThreads[0].Context : 0;
  569. create_window(&WinThreads[i], share);
  570. }
  571. printf("glthreads: creating threads\n");
  572. /* Create the threads */
  573. for (i = 0; i < numThreads; i++) {
  574. pthread_create(&WinThreads[i].Thread, NULL, thread_function,
  575. (void*) &WinThreads[i]);
  576. printf("glthreads: Created thread %p\n", (void *) WinThreads[i].Thread);
  577. }
  578. if (MultiDisplays)
  579. event_loop_multi();
  580. else
  581. event_loop(dpy);
  582. clean_up();
  583. if (MultiDisplays) {
  584. for (i = 0; i < numThreads; i++) {
  585. XCloseDisplay(WinThreads[i].Dpy);
  586. }
  587. }
  588. else {
  589. XCloseDisplay(dpy);
  590. }
  591. return 0;
  592. }
  593. #else /* PTHREADS */
  594. #include <stdio.h>
  595. int
  596. main(int argc, char *argv[])
  597. {
  598. printf("Sorry, this program wasn't compiled with PTHREADS defined.\n");
  599. return 0;
  600. }
  601. #endif /* PTHREADS */