Permalink
Browse files

Merged patches to main trunk.

  • Loading branch information...
rpj
rpj committed Aug 12, 1999
1 parent cbbe471 commit 57c48ca47cc5084bd28511ecf06bc93fa4ea7811
Showing with 279 additions and 72 deletions.
  1. +29 −24 ANNOUNCE
  2. +13 −0 CONTRIBUTORS
  3. +40 −0 ChangeLog
  4. +3 −13 MAINTAINERS
  5. +2 −2 cancel.c
  6. +42 −10 condvar.c
  7. +55 −2 exit.c
  8. +17 −5 implement.h
  9. +2 −2 misc.c
  10. +61 −12 private.c
  11. +9 −1 pthread.h
  12. +4 −0 tests/ChangeLog
  13. +2 −1 tests/Makefile
View
@@ -9,8 +9,8 @@
We are pleased to announce the availability of a new snapshot of
Pthreads-win32, an Open Source Software (OSS) implementation of the
Threads component of the POSIX 1003.1c 1995 Standard for Microsoft's
-Win32 environment. Some functions from POSIX 1003.1b are supported
-including semaphores.
+Win32 environment. Some functions from POSIX 1003.1b are also
+supported including semaphores.
Pthreads-win32 is free software, distributed under the GNU Library
General Public License (LGPL).
@@ -27,7 +27,7 @@ Change Summary (since the last snapshot)
Some minor bugs have been fixed. See the ChangeLog file for details.
-Some more POSIX 1b functions are now included but ony return an
+Some more POSIX 1b functions are now included but only return an
error (ENOSYS) if called. They are:
sem_open
@@ -267,7 +267,7 @@ MSVC:
MSVC works.
Mingw32: (ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/egcs-1.1.1/)
-Mingw32 must use the thread-safe MSVCRT library. You can link
+Mingw32 must use the thread-safe MSVCRT library (see the FAQ). You can link
against the export library libpthread32.a built under Mingw32
but you must run your application with the version of pthread.dll built
with MSVC.
@@ -281,41 +281,46 @@ pthreads-win32 against Cygwin.
Generally:
For convenience, the following pre-built files are available on the FTP site
-(see above):
+(see Availability above):
pthread.h - for POSIX 1c threads
semaphore.h - for POSIX 1b semaphores
sched.h - for POSIX 1b scheduling
- pthread.dll - built with MSVC cl compiler
- pthread.lib - built with MSVC cl compiler
- libpthread32.a - built with Mingw32 (use with MSVC pthread.dll)
-
+ pthread.dll - built with MSVC cl compiler on NT4.0
+ pthread.lib - built with MSVC cl compiler on NT4.0
+ libpthread32.a - built with Mingw32 on Win98 (use with
+ MSVC pthread.dll for runtime)
+
These are the only files you need in order to build POSIX threads
applications for Win32 using either MSVC or Mingw32.
See the FAQ file in the source tree for additional information.
-
-Building the library with MSVC
--------------------------------
-
-There is currently no Makefile for building the library under MSVC.
-There is a batch file "buildlib.bat" which will build the library.
-
-Why you can't build the library with Cygwin or Mingw32 (yet)
-------------------------------------------------------------
-
+Why you can't build the DLL itself with Mingw32 (yet)
+-----------------------------------------------------
+
The library makes use of exception handling internally (Win32 SEH if
compiled with MSVC and C++ EH otherwise). Unfortunately, current
versions of egcs (g++) do not have thread-safe exception handling
-and therefore the DLL pthread.dll cannot be built under either
-Mingw32 or Cygwin.
-
-
+and therefore the DLL pthread.dll cannot be built.
+
+However, it is possible to build applications which make use of
+pthreads-win32, using Mingw32's gcc or g++.
+
+
+Building the library with MSVC
+------------------------------
+
+There is currently no Makefile for building the library under MSVC.
+This is partly because my access to MSVC is via telnet to a remote NT
+machine. There is a batch file "buildlib.bat" which will build the
+library.
+
+
Documentation
-------------
-
+
Currently, there is no documentation included in the package apart
from the copious comments in the source code.
View
@@ -0,0 +1,13 @@
+Contributors (in approximate order of appearance)
+
+Ben Elliston bje@cygnus.com
+Ross Johnson rpj@ise.canberra.edu.au
+Robert Colquhoun rjc@trump.net.au
+John E. Bossom John.Bossom@cognos.com
+Anders Norlander anorland@hem2.passagen.se
+Tor Lillqvist tml@iki.fi
+Kevin Ruland Kevin.Ruland@anheuser-busch.com
+Mike Russo miker@eai.com
+Mark E. Armstrong avail@pacbell.net
+Lorin Hochstein lmh@xiphos.ca
+Peter Slacik Peter.Slacik@tatramed.sk
View
@@ -1,3 +1,43 @@
+1999-08-12 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
+
+ * exit.c (pthread_exit): Check for implicitly created threads
+ to avoid raising an unhandled exception.
+
+1999-07-12 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
+
+ * condvar.c (pthread_cond_destroy): Add critical section.
+ (cond_timedwait): Add critical section; check for timeout
+ waiting on semaphore.
+ (pthread_cond_broadcast): Add critical section.
+ - Peter Slacik <Peter.Slacik@tatramed.sk>
+
+1999-07-09 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
+
+ The following changes fix a bug identified by
+ Lorin Hochstein <lmh@xiphos.ca> and solved by
+ John Bossom <John.Bossom@Cognos.COM>.
+
+ The problem was that cleanup handlers were not executed when
+ pthread_exit() was called.
+
+ * implement.h (pthread_t_): Add exceptionInformation element for
+ C++ per-thread exception information.
+ (general): Define and rename exceptions.
+
+
+ * misc.c (CancelableWait): _PTHREAD_EPS_CANCEL (SEH) and
+ Pthread_exception_cancel (C++) used to identify the exception.
+
+ * cancel.c (pthread_testcancel): _PTHREAD_EPS_CANCEL (SEH) and
+ Pthread_exception_cancel (C++) used to identify the exception.
+
+ * exit.c (pthread_exit): throw/raise an exception to return to
+ _pthread_threadStart() to exit the thread. _PTHREAD_EPS_EXIT (SEH)
+ and Pthread_exception_exit (C++) used to identify the exception.
+
+ * private.c (_pthread_threadStart): Add pthread_exit exception trap;
+ clean up and exit the thread directly rather than via pthread_exit().
+
Sun May 30 00:25:02 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* semaphore.h (mode_t): Conditionally typedef it.
View
@@ -1,14 +1,4 @@
- Maintainers
+CVS Repository maintainers
-Write permission
-
-Ben Elliston bje@cygnus.com
-Ross Johnson rpj@ise.canberra.edu.au
-
-Contributors (in order of appearance)
-
-Robert Colquhoun rjc@trump.net.au
-John E. Bossom John.Bossom@cognos.com
-Anders Norlander anorland@hem2.passagen.se
-Tor Lillqvist tml@iki.fi
-Kevin Ruland Kevin.Ruland@anheuser-busch.com
+Ross Johnson rpj@ise.canberra.edu.au
+Ben Elliston bje@cygnus.com
View
@@ -195,7 +195,7 @@ pthread_testcancel (void)
DWORD exceptionInformation[3];
- exceptionInformation[0] = (DWORD) (0);
+ exceptionInformation[0] = (DWORD) (_PTHREAD_EPS_CANCEL);
exceptionInformation[1] = (DWORD) (0);
exceptionInformation[2] = (DWORD) (0);
@@ -209,7 +209,7 @@ pthread_testcancel (void)
#ifdef __cplusplus
- throw Pthread_exception();
+ throw Pthread_exception_cancel();
#endif /* __cplusplus */
View
@@ -459,14 +459,21 @@ pthread_cond_destroy (pthread_cond_t * cond)
if (cv != (pthread_cond_t) _PTHREAD_OBJECT_AUTO_INIT)
{
+ if (pthread_mutex_lock(&(cv->waitersLock)) != 0)
+ {
+ return EINVAL;
+ }
+
if (cv->waiters > 0)
{
+ (void) pthread_mutex_unlock(&(cv->waitersLock));
return EBUSY;
}
(void) sem_destroy (&(cv->sema));
- (void) pthread_mutex_destroy (&(cv->waitersLock));
(void) CloseHandle (cv->waitersDone);
+ (void) pthread_mutex_unlock(&(cv->waitersLock));
+ (void) pthread_mutex_destroy (&(cv->waitersLock));
free(cv);
}
@@ -510,10 +517,22 @@ cond_timedwait (pthread_cond_t * cond,
cv = *cond;
/*
- * OK to increment cond->waiters because the caller locked 'mutex'
+ * It's not OK to increment cond->waiters while the caller locked 'mutex',
+ * there may be other threads just waking up (with 'mutex' unlocked)
+ * and cv->... data is not protected.
*/
+ if (pthread_mutex_lock(&(cv->waitersLock)) != 0)
+ {
+ return EINVAL;
+ }
+
cv->waiters++;
+ if (pthread_mutex_unlock(&(cv->waitersLock)) != 0)
+ {
+ return EINVAL;
+ }
+
/*
* We keep the lock held just long enough to increment the count of
* waiters by one (above).
@@ -527,6 +546,7 @@ cond_timedwait (pthread_cond_t * cond,
* Wait to be awakened by
* pthread_cond_signal, or
* pthread_cond_broadcast
+ * timeout
*
* Note:
* _pthread_sem_timedwait is a cancellation point,
@@ -548,18 +568,18 @@ cond_timedwait (pthread_cond_t * cond,
if ((internal_result = pthread_mutex_lock (&(cv->waitersLock))) == 0)
{
/*
- * By making the waiter responsible for decrementing
- * its count we don't have to worry about having an internal
- * mutex.
+ * The waiter is responsible for decrementing
+ * its count, protected by an internal mutex.
*/
+
cv->waiters--;
lastWaiter = cv->wasBroadcast && (cv->waiters == 0);
internal_result = pthread_mutex_unlock (&(cv->waitersLock));
}
- if (result == 0 && internal_result == 0)
+ if ((result == 0 || result == ETIMEDOUT) && internal_result == 0)
{
if (lastWaiter)
{
@@ -576,7 +596,7 @@ cond_timedwait (pthread_cond_t * cond,
/*
* We must always regain the external mutex, even when
- * errors occur because that's the guarantee that we give
+ * errors occur, because that's the guarantee that we give
* to our callers
*/
(void) pthread_mutex_lock (mutex);
@@ -760,6 +780,7 @@ pthread_cond_signal (pthread_cond_t * cond)
/*
* No-op if the CV is static and hasn't been initialised yet.
+ * Assuming that race conditions are harmless.
*/
if (cv == (pthread_cond_t) _PTHREAD_OBJECT_AUTO_INIT)
{
@@ -768,6 +789,7 @@ pthread_cond_signal (pthread_cond_t * cond)
/*
* If there aren't any waiters, then this is a no-op.
+ * Assuming that race conditions are harmless.
*/
if (cv->waiters > 0)
{
@@ -817,6 +839,7 @@ pthread_cond_broadcast (pthread_cond_t * cond)
*/
{
int result = 0;
+ int wereWaiters = FALSE;
pthread_cond_t cv;
if (cond == NULL || *cond == NULL)
@@ -828,13 +851,20 @@ pthread_cond_broadcast (pthread_cond_t * cond)
/*
* No-op if the CV is static and hasn't been initialised yet.
+ * Assuming that any race condition is harmless.
*/
if (cv == (pthread_cond_t) _PTHREAD_OBJECT_AUTO_INIT)
{
return 0;
}
+ if (pthread_mutex_lock(&(cv->waitersLock)) == EINVAL)
+ {
+ return EINVAL;
+ }
+
cv->wasBroadcast = TRUE;
+ wereWaiters = (cv->waiters > 0);
/*
* Wake up all waiters
@@ -843,14 +873,16 @@ pthread_cond_broadcast (pthread_cond_t * cond)
? 0
: EINVAL);
- if (cv->waiters > 0 && result == 0)
+ (void) pthread_mutex_unlock(&(cv->waitersLock));
+
+ if (wereWaiters && result == 0)
{
/*
* Wait for all the awakened threads to acquire their part of
* the counting semaphore
*/
- if (WaitForSingleObject (cv->waitersDone, INFINITE) ==
- WAIT_OBJECT_0)
+ if (WaitForSingleObject (cv->waitersDone, INFINITE)
+ == WAIT_OBJECT_0)
{
result = 0;
}
Oops, something went wrong.

0 comments on commit 57c48ca

Please sign in to comment.