Subject: Re: exit() strangeness with pth thread package...
To: Todd Vierling <tv@wasabisystems.com>
From: Brian Stark <bstark@siemens-psc.com>
List: netbsd-help
Date: 10/14/2000 12:34:58
On Fri, 13 Oct 2000, Todd Vierling wrote:

> The pthread emulation in pth, while gleefully portable, is *NOT* POSIX
> threads.  pth uses *cooperative* scheduling, so expecting exit(2) to Just
> Exit may depend on some things.  I'd need to see the full source to be sure
> you aren't still spinning the CPU in some thread.

How does the scheduling work in pth? From what I have seen during my
testing on NetBSD is that if I create multiple threads the thread that is
currently running doesn't seem to yield the CPU to the other threads, thus
the program appears to be single threaded. When I run my threaded programs
on AIX (using the native pthread implementation), I can see each of my
threads running. 

The program I have been developing basically creates a queue of items to
be processed and then creates a group of worker threads that access the
queue and pull items off to be processed. With NetBSD the first worker
thread always processes the entire queue but under AIX I see the other
worker threads pulling items off the queue. The behavior under AIX is what
I am expecting to see under NetBSD.

I spent some more time on my test program that was stuck in the loop --
there was one data structure that contained a mutex that had been destoyed
before pthread_mutex_destroy() had been called. Once I corrected that, my
test program ran fine. Multiple threads were not created, I was only
testing the ability to dynamically create a mutex to implement a locking
mechanism for functions that are not thread-safe/re-entrant. One problem I
have been having since I have started working with threads is that
different versions of UNIX (AIX, *BSD, solaris, etc...) all seem to have
different sets of thread safe/re-entrant functions. Writing portable code
for different platforms is a bit difficult when certain functions exist on
one platform and not another. What I am hoping to accomplish is to come up
with a small library that I can use on multiple platforms that would work
something like this:

  lock_function("syslog");    // create and lock a mutex for 'syslog'
  syslog(LOG_DEBUG,"Hello World");
  unlock_function("syslog");  // unlock and destroy mutex for 'syslog'


Brian

-------------------------------------------------------------------------
| Brian Stark  Siemens Power Transmission & Distribution, Inc.          |
|              Energy Management and Information Systems Division       |
|              7225 Northland Drive, Brooklyn Park, Minnesota 55428 USA |
| email: bstark@siemens-psc.com +1 763 536-4697 fax: +1 763 536-4919    |
-------------------------------------------------------------------------