From owner-FreeBSD-users-jp@jp.freebsd.org  Wed Sep 23 18:16:41 1998
Received: (from daemon@localhost)
	by jaz.jp.freebsd.org (8.9.1+3.0W/8.7.3) id SAA10953;
	Wed, 23 Sep 1998 18:16:41 +0900 (JST)
	(envelope-from owner-FreeBSD-users-jp@jp.FreeBSD.org)
Received: from ma2.seikyou.ne.jp (ma2.seikyou.ne.jp [202.211.152.197])
	by jaz.jp.freebsd.org (8.9.1+3.0W/8.7.3) with ESMTP id SAA10947
	for <FreeBSD-users-jp@jp.freebsd.org>; Wed, 23 Sep 1998 18:16:39 +0900 (JST)
	(envelope-from ysonoda@dontaku.csce.kyushu-u.ac.jp)
Received: from hornet.navy.or.jp (us-031.seikyou.ne.jp [202.33.58.31])
	by ma2.seikyou.ne.jp (8.8.8/3.6WNSK98032401) with ESMTP id SAA31670
	for <FreeBSD-users-jp@jp.freebsd.org>; Wed, 23 Sep 1998 18:16:38 +0900
Received: from localhost (localhost [127.0.0.1])
	by hornet.navy.or.jp (8.8.8/3.6W) with ESMTP id SAA13214
	for <FreeBSD-users-jp@jp.freebsd.org>; Wed, 23 Sep 1998 18:16:37 +0900 (JST)
To: FreeBSD-users-jp@jp.freebsd.org
From: SONODA Yoshihide (=?iso-2022-jp?B?GyRCMWBFRBsoQiAbJEI1SDFRGyhC?=) <ysonoda@dontaku.csce.kyushu-u.ac.jp>
X-Mailer: Mew version 1.93 on XEmacs 20.4 (Emerald)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Message-Id: <19980923181636K.ysonoda@dontaku.csce.kyushu-u.ac.jp>
Date: Wed, 23 Sep 1998 18:16:36 +0900
X-Dispatcher: imput version 980905(IM100)
Lines: 99
Reply-To: FreeBSD-users-jp@jp.freebsd.org
Precedence: bulk
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+980914
X-Sequence: FreeBSD-users-jp 33206
Subject: [FreeBSD-users-jp 33206] pthread & thread safe Xlib
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org

$B1`ED!w6eBg$G$9!#(B

$B8=:_!"$H$"$k(BLinux$B$N(BMulti Thread$B$J%W%m%0%i%`$r(BFreeBSD$B$K0\?"$7$F$$$^$9!#(B
X$B$r;H$o$J$$ItJ,$O$[$\F0$/$h$&$K$J$C$?$N$G$9$,!"(BX$B$r;H$C$?ItJ,$,F0$$$F(B
$B$/$l$^$;$s!#(B

$B6qBNE*$K$O!"0J2<$N$h$&$J%W%m%0%i%`$rF0$+$7$F$_$k$H!"(B

-------------------------------------------------------- test.cc
#include <iostream>
#include <X11/Xlib.h>
#include <pthread.h>

using namespace std;

void* waitEvent (void* display__)
{
  Display* display = static_cast<Display*> (display__);
  int screen = DefaultScreen (display);
  Window window = XCreateSimpleWindow (display, XDefaultRootWindow (display),
				       0, 0, 100, 100, 0,
				       BlackPixel (display, screen),
				       WhitePixel (display, screen));
  XSelectInput (display, window, ExposureMask);
  XMapWindow (display, window);
  XFlush (display);

  const int MAX_EXPOSURE = 10;
  int count = 0;
  while (count < MAX_EXPOSURE)
    {
      XEvent event;
      XWindowEvent (display, window, ExposureMask, &event);
      //XNextEvent (display, &event);
      cout << "exposed " << count << "-times"<< endl;
      count++;
    }

  return NULL;
}

int main ()
{
  Display* display = XOpenDisplay (NULL);
  //XSynchronize (display, 1);

  const int MAX_THREADS = 2;
  pthread_t thread[MAX_THREADS];
  for (int i = 0; i < MAX_THREADS; i++)
    {
      cout << i << "-th thread creating" << endl;
      pthread_create (&thread[i], NULL,
		      &waitEvent, static_cast<void*> (display));
    }

  for (int i = 0; i < MAX_THREADS; i++)
    {
      pthread_join (thread[i], NULL);
      cout << i << "-th thread joined" << endl;
    }
}

------------------------------------------end of test.cc

$B!J%3%s%Q%$%i$O(B egcs 1.1b $B$r;HMQ$7$F$$$^$9!#!K(B
% eg++ -D_RENTRANT -I/usr/X11R6/include test.cc -L/usr/X11R6/lib -lX11 -lc_r
% ./a.out
0-th thread creating
1-th thread creating
exposed 0-times
XIO:  fatal IO error 0 (Undefined error: 0) on X server ":0.0"
      after 13 requests (13 known processed) with 0 events remaining.

$B$H$J$C$F(B Window $B$,I=<($5$l$:$K=*$o$C$F$7$^$$$^$9!#(B
Linux$B$G$O$-$A$s$HF0$/$=$&$G$9!#(B

FreeBSD $B$O(B 2.2.7-RELEASE$B!"(BXFree86 $B$O(B 3.3.2.3 $B$G(B
host.def $B$K(B
#define HasPosixThreads         YES
#define ThreadedX               YES
#define HasThreadSafeAPI        YES
#define ThreadsLibraries        -lc_r
#define SystemMTDefines         -D_REENTRANT
$B$H2C$($F(B make World $B$7!"(Bthread safe $B$K$7$?$D$b$j$G$9!#(B

$B$3$l$O(B Thread Safe $B$J(B Xlib $B$r:n$jB;$J$C$F$$$k$N$G$7$g$&$+!)(B
$B$@$H$7$?$i!"(Bhost.def $B$K$O$I$N$h$&$J%*%W%7%g%s$r;XDj$9$l$P$$$$$N$G$7$g$&$+!)(B
$B$^$?$O!"B>$K860x$,$"$k$N$G$7$g$&$+!)(B 

$B;29M(B:
$B0\?"Cf$N%W%m%0%i%`(B
http://www.kusm.kyoto-u.ac.jp/~yamahata/widi/index.html
$B:n<T$NJ}$K$b6(NO$7$F$b$i$C$F$$$^$9!#(B

---
$B6e=#Bg3XBg3X1!(B $B%7%9%F%`>pJs2J3X8&5f2J(B $B>pJs9)3X@l96(B $B=$;N(B1$BG/(B 
           $B1`ED(B $B5H1Q(B (Sonoda, Yoshihide)
     E-mail: ysonoda@dontaku.csce.kyushu-u.ac.jp
   URL: http://dontaku.csce.kyushu-u.ac.jp/~ysonoda/
