Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Jan 1999 18:46:55 -0800 (PST)
From:      Marcia Perry (ITG staff) <mperry@george.lbl.gov>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Pthreads Problems
Message-ID:  <199901050246.SAA21135@george.lbl.gov>

next in thread | raw e-mail | index | archive | help
Hi,

I'm writing an app in C++ using Pthreads.  The code works nicely
under Solaris so I figure I must be doing something correctly!
However, under freeBSD, release 2.2.6, I'm experiencing the
following problems and would like your advice:

1).  I declare global variables:
	pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
	pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

     and get these errors during the build:

	"devserv.cc:69: `PTHREAD_MUTEX_INITIALIZER' was not declared in this scope
devserv.cc:70: `PTHREAD_COND_INITIALIZER' was not declared in this scope
"

     My compile/link command line is:
	CC -D_THREAD_SAFE -o devserv file1.cc file2.cc ... -lc_r

     Yes, I double-checked that I am including <pthread.h>

     According to Dave Butenhof's "Programming with POSIX Threads" book,
     static initialization of mutexes and condition variables should be ok.
     So why is freeBSD, rel. 2.2.6 forcing me into dynamic initialization?

     Is my build command wrong or incomplete?  Look like a problem with
     my environment?


2).  The app is a server that takes requests from remote clients and
     communicates with serial devices (e.g., cameras) to carry out
     these requests (e.g., pan or tilt a camera).  So I have several
     devices attached to my computer and I listen on several network
     sockets for remote requests.  I use threads to do blocked recvfrom()'s
     on each socket, signal when a request is added to a list, and do
     the typical stuff (e.g., main() gets the signal and processes
     the request).  No problems here.  But this scenario forces me to
     terminate only when user types a contrl character (cntl-C, e.g.)
     or if I blow it and seg fault or bus error...  So, in a single-
     threaded version, I had a nice signal handler to catch SIGINT,
     SIGSEGV, etc., and before exiting, turning off the cameras, one
     at a time.

     In the threaded version, I have been advised NOT to use a signal
     handler.  Rather, create a thread to wait for the signals in
     a sigset_t variable (and call sigwait()).  And mask out the
     signals from all the other threads that you do NOT want to catch
     them.  Fine.  So I copied D. Butenhof's source code (page 228)
     from his book to see how this was done.  It works great under
     Solaris.  Under freeBSD, at least for version 2.2.6, sigwait()
     doesn't seem to work -- I never get the SIGINT and need to
     terminate with the manual "ps" and "kill" commands.  

     Is this a bug under release 2.2.6?

3).  I looked at pthread.h to see how pthread_t is defined and did
     see it typedef'd as a pointer to a structure.  But searching
     through all the headers did not reveal the definition of that
     pthread_t structure.  And I couldn't find sigwait() in either
     the man pages nor the headers.  However, the following
     showed the sigwait() function to be defined and located in
     -lc_r --

mperry@zippy(87)>nm -p libc_r.so.3.0 | grep sigwait
libc_r.so.3.0:00000280 T _sigwait


     Where then is sigwait() defined/documented? 

Thanks for your time and help--
Marcia

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901050246.SAA21135>