From 6eb5bba145940501ca972e4243d7417c8120d569 Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 6 Aug 2000 12:15:47 +0000 Subject: 2000-08-06 Ross Johnson * pthread.h: Remove #warning - VC++ doesn't accept it. 2000-08-05 Ross Johnson * pthread.h (PtW32CatchAll): Add macro. When compiling applications using VC++ with C++ EH rather than SEH 'PtW32CatchAll' must be used in place of any 'catch( ... )' if the application wants pthread cancelation or pthread_exit() to work. 2000-08-03 Ross Johnson * pthread.h: Add a base class Pthread_exception for library internal exceptions and change the "catch" re-define macro to use it. 2000-08-02 Ross Johnson * GNUmakefile (CFLAGS): Add -mthreads. Add new targets to generate cpp and asm output. * sync.c (pthread_join): Remove dead code. tests: 2000-08-06 Ross Johnson * ccl.bat: Add /nologo to remove extraneous output. * exception1.c (exceptionedThread): Init 'dummy'; put expression into if condition to prevent optimising away; remove unused variable. * cancel4.c (mythread): Cast return value to avoid warnings. * cancel2.c (mythread): Missing #endif. * condvar9.c (mythread): Cast return value to avoid warnings. * condvar8.c (mythread): Cast return value to avoid warnings. * condvar7.c (mythread): Cast return value to avoid warnings. * cleanup3.c (mythread): Cast return value to avoid warnings. * cleanup2.c (mythread): Cast return value to avoid warnings. * cleanup1.c (mythread): Cast return value to avoid warnings. * condvar5.c (mythread): Cast return value to avoid warnings. * condvar3.c (mythread): Cast return value to avoid warnings. * condvar6.c (mythread): Cast return value to avoid warnings. * condvar4.c (mythread): Cast return value to avoid warnings. 2000-08-05 Ross Johnson * cancel2.c: Use PtW32CatchAll macro if defined. * exception1.c: Use PtW32CatchAll macro if defined. 2000-08-02 Ross Johnson * tsd1.c: Fix typecasts of &result [g++ is now very fussy]. * test.h (assert): Return 0's explicitly to allay g++ errors. * join2.c: Add explicit typecasts. * join1.c: Add explicit typecasts. * join0.c: Add explicit typecasts. * eyal1.c: Add explicit typecasts. * count1.c (main): Add type cast to remove g++ parse warning [gcc-2.95.2 seems to have tightened up on this]. * Makefile (GLANG): Use c++ explicitly. Remove MSVC sections (was commented out). Add target to generate cpp output. --- ChangeLog | 25 ++++++ FAQ | 33 +++----- GNUmakefile | 148 +++++++++++++++++----------------- buildlib.bat | 51 ++++++------ private.c | 13 ++- pthread.h | 36 +++++---- sync.c | 16 +--- tests/ChangeLog | 60 ++++++++++++++ tests/Makefile | 230 ++++++++++++++++++++++++++--------------------------- tests/cancel2.c | 8 +- tests/cancel4.c | 2 +- tests/ccl.bat | 2 +- tests/cleanup1.c | 2 +- tests/cleanup2.c | 2 +- tests/cleanup3.c | 2 +- tests/condvar3.c | 2 +- tests/condvar4.c | 2 +- tests/condvar5.c | 2 +- tests/condvar6.c | 2 +- tests/condvar7.c | 2 +- tests/condvar8.c | 2 +- tests/condvar9.c | 2 +- tests/count1.c | 2 +- tests/exception1.c | 27 +++++-- tests/eyal1.c | 5 +- tests/join0.c | 2 +- tests/join1.c | 2 +- tests/join2.c | 2 +- tests/test.h | 4 +- tests/tsd1.c | 2 +- 30 files changed, 390 insertions(+), 300 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a1a53c..dd08605 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2000-08-06 Ross Johnson + + * pthread.h: Remove #warning - VC++ doesn't accept it. + +2000-08-05 Ross Johnson + + * pthread.h (PtW32CatchAll): Add macro. When compiling + applications using VC++ with C++ EH rather than SEH + 'PtW32CatchAll' must be used in place of any 'catch( ... )' + if the application wants pthread cancelation or + pthread_exit() to work. + +2000-08-03 Ross Johnson + + * pthread.h: Add a base class Pthread_exception for + library internal exceptions and change the "catch" + re-define macro to use it. + +2000-08-02 Ross Johnson + + * GNUmakefile (CFLAGS): Add -mthreads. + Add new targets to generate cpp and asm output. + + * sync.c (pthread_join): Remove dead code. + 2000-07-25 Ross Johnson * sched.c (sched_get_priority_max): Handle different WinCE and diff --git a/FAQ b/FAQ index f6da212..1f0c8a3 100644 --- a/FAQ +++ b/FAQ @@ -27,10 +27,9 @@ A 1 --- Important: see Q2 also. -I short, use Mingw32 with the MSVCRT library to build applications that use -the DLL. You cannot build the library itself with either yet because the -library uses C++ EH which is not thread-safe in egcs yet. Use MSVC or grab -the pre-build DLL etc. +In short, use Mingw32 with the MSVCRT library to build applications that use +the DLL. Cygwin's own internal support for POSIX threads is growing. Consult +that project's documentation for more information. Date: Mon, 07 Dec 1998 15:11:37 +0100 From: Anders Norlander @@ -89,11 +88,14 @@ Q 2 Now that pthreads-win32 builds under Mingw32, why do I get A 2 --- +Note: +The latest Mingw32 package now has thread-safe exception handling. + The following email exchange describes the problem. Until this issue is resolved people without the Microsoft compiler can obtain the current MSVC prebuilt DLL (pthread.{dll,lib,h}) at: -ftp://sourceware.cygnus.com/pub/pthreads-win32/dll-latest +ftp://sources.redhat.com/pub/pthreads-win32/dll-latest Date: Wed, 10 Feb 1999 13:21:01 -0000 From: "Ruland, Kevin" @@ -133,16 +135,8 @@ For Mingw crtdll/msvc, someone needs to write the thread-wrapper for win32 threads. Anyone who knows win32 threads should be able to do this without much trouble at all. It's low on my priority list, so unless someone else volunteers, it'll have to wait. - -Are you willing to take a look? If so, I can provide details. <\Quote> -And there you have it! To summarize, it's nice that pthreads compile but they -aren't much use just yet. - -I'll respond to Mumit with 'Okay, what do I need to look at', but may not be -able to tackle it myself. - Kevin ------------------------------------------------------------------------------ @@ -191,7 +185,6 @@ Q 4 Cancelation doesn't work for me, why? A 4 --- - > I'm investigating a problem regarding thread cancelation. The thread I want > to cancel has PTHREAD_CANCEL_ASYNCHRONOUS, however, this piece of code > blocks on the join(): @@ -214,6 +207,9 @@ A 4 > win32 programming, so I don't really understand how the *Event() family of > calls work. +Async cancelation should be in post-snapshot-1999-11-02 versions +of pthreads-win32 (currently only for x86 architectures). + The answer to your first question is, normal POSIX behaviour would be to asynchronously cancel the thread. However, even that doesn't guarantee cancelation as the standard only says it should be @@ -221,9 +217,9 @@ cancelled as soon as possible. However ... -Pthreads-win32 only partially supports asynchronous cancellation. If the -thread you're trying to cancel is blocked (for instance, it could be waiting -for data from the network), it will only get cancelled when it unblocks +Snapshot 99-11-02 or earlier only partially supports asynchronous cancellation. +If the thread you're trying to cancel is blocked (for instance, it could be +waiting for data from the network), it will only get cancelled when it unblocks (when the data arrives). Unfortunately, there is no way to do so from outside the thread. @@ -264,7 +260,6 @@ Q 5 Thread won't block after two calls to mutex_lock A 5 --- - > i was testing this pthread for win32 in my prog. > when i checked if it was blocking mutex_lock calls, i was surprised when it > didnt lock @@ -304,7 +299,6 @@ Q 6 How do I generate libpthread.a for use with Mingw32? A 6 --- - > I'm lacking the libpthread.a that > used to come with the pre-compiled package. The last time this > library appeared was in 1999-08-12. Without this library I cannot @@ -320,4 +314,3 @@ Where DLLTOOL is i686-pc-cygwin-dlltool and AS i686-pc-cygwin-as. Thomas Sailer - diff --git a/GNUmakefile b/GNUmakefile index 4c94cc7..1405942 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,71 +1,77 @@ -# -# Pthreads-win32 - POSIX Threads Library for Win32 -# Copyright (C) 1998 -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Library General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Library General Public License for more details. -# -# You should have received a copy of the GNU Library General Public -# License along with this library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -# MA 02111-1307, USA -# - -GLANG = c++ - -RM = erase - -CC = gcc - -AR = ar - -LD = gcc -mdll - -OPT = -g -O2 -x $(GLANG) - -## Mingw32 -CFLAGS = $(OPT) -I. -DHAVE_CONFIG_H -Wall - -## Cygwin G++ -#CFLAGS = $(OPT) -fhandle-exceptions -I. -DHAVE_CONFIG_H -Wall - -OBJS = attr.o cancel.o cleanup.o condvar.o create.o dll.o errno.o \ - exit.o fork.o global.o misc.o mutex.o private.o rwlock.o \ - sched.o semaphore.o signal.o sync.o tsd.o - -INCL = implement.h semaphore.h pthread.h windows.h - -DLL = pthread.dll - -LIB = libpthread32.a - - -all: $(LIB) - -$(LIB): $(DLL) - dlltool --def $(DLL:.dll=.def) --output-lib $@ --dllname $(DLL) - -.SUFFIXES: .dll - -$(DLL): $(OBJS) - $(LD) -o $@ $^ -Wl,--base-file,$*.base - dlltool --base-file=$*.base --def $*.def --output-exp $*.exp --dllname $@ - $(LD) -o $@ $^ -Wl,--base-file,$*.base,$*.exp - dlltool --base-file=$*.base --def $*.def --output-exp $*.exp --dllname $@ - $(LD) -o $@ $^ -Wl,$*.exp - -clean: - -$(RM) *~ - -$(RM) $(LIB) - -$(RM) *.o - -$(RM) *.exe - -$(RM) $(DLL) - -$(RM) $(DLL:.dll=.base) - -$(RM) $(DLL:.dll=.exp) +# +# Pthreads-win32 - POSIX Threads Library for Win32 +# Copyright (C) 1998 +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +# MA 02111-1307, USA +# + +GLANG = c++ + +RM = erase + +CC = gcc + +AR = ar + +LD = gcc -mdll + +OPT = -g -O2 -x $(GLANG) + +## Mingw32 +CFLAGS = $(OPT) -I. -mthreads -DHAVE_CONFIG_H -Wall + +## Cygwin G++ +#CFLAGS = $(OPT) -fhandle-exceptions -I. -DHAVE_CONFIG_H -Wall + +OBJS = attr.o cancel.o cleanup.o condvar.o create.o dll.o errno.o \ + exit.o fork.o global.o misc.o mutex.o private.o rwlock.o \ + sched.o semaphore.o signal.o sync.o tsd.o + +INCL = implement.h semaphore.h pthread.h windows.h + +DLL = pthread.dll + +LIB = libpthread32.a + + +all: $(LIB) + +$(LIB): $(DLL) + dlltool --def $(DLL:.dll=.def) --output-lib $@ --dllname $(DLL) + +%.pre: %.c + $(CC) -E -o $@ $(CFLAGS) $^ + +%.s: %.c + $(CC) -c $(CFLAGS) -Wa,-ahl $^ > $@ + +.SUFFIXES: .dll + +$(DLL): $(OBJS) + $(LD) -o $@ $^ -Wl,--base-file,$*.base + dlltool --base-file=$*.base --def $*.def --output-exp $*.exp --dllname $@ + $(LD) -o $@ $^ -Wl,--base-file,$*.base,$*.exp + dlltool --base-file=$*.base --def $*.def --output-exp $*.exp --dllname $@ + $(LD) -o $@ $^ -Wl,$*.exp + +clean: + -$(RM) *~ + -$(RM) $(LIB) + -$(RM) *.o + -$(RM) *.exe + -$(RM) $(DLL) + -$(RM) $(DLL:.dll=.base) + -$(RM) $(DLL:.dll=.exp) diff --git a/buildlib.bat b/buildlib.bat index c2c5c4f..63eea0a 100644 --- a/buildlib.bat +++ b/buildlib.bat @@ -1,24 +1,27 @@ -del *.obj - -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c attr.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c cancel.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c cleanup.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c condvar.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c create.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c dll.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c exit.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c fork.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c global.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c misc.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c mutex.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c private.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c sched.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c signal.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c sync.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c tsd.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c semaphore.c -cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c rwlock.c - -cl /LD /Zi *.obj /Fepthread.dll /link /nodefaultlib:libcmt /implib:pthread.lib msvcrt.lib /def:pthread.def - - +del *.obj +del pthread.dll + +set EH= + +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c attr.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c cancel.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c cleanup.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c condvar.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c create.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c dll.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c exit.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c fork.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c global.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c misc.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c mutex.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c private.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c sched.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c signal.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c sync.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c tsd.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c semaphore.c +cl /W3 %EH% /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c rwlock.c + +cl /LD %EH% /Zi *.obj /Fepthread.dll /link /nodefaultlib:libcmt /implib:pthread.lib msvcrt.lib /def:pthread.def + + diff --git a/private.c b/private.c index f374e27..03d27c3 100644 --- a/private.c +++ b/private.c @@ -184,11 +184,8 @@ _pthread_threadStart (ThreadParms * threadParms) pthread_t self; void *(*start) (void *); void *arg; - #ifdef _MSC_VER - DWORD ei[] = {0,0,0}; - #endif void * status; @@ -249,7 +246,8 @@ _pthread_threadStart (ThreadParms * threadParms) { /* * A system unexpected exception had occurred running the user's - * routine. We get control back within this block. + * routine. We get control back within this block because + * we can't allow the exception out of thread scope. */ status = PTHREAD_CANCELED; } @@ -271,7 +269,7 @@ _pthread_threadStart (ThreadParms * threadParms) /* * Thread was cancelled. */ - status = PTHREAD_CANCELED; + status = self->exitStatus = PTHREAD_CANCELED; } _pthread_catch (Pthread_exception_exit) { @@ -284,9 +282,10 @@ _pthread_threadStart (ThreadParms * threadParms) { /* * A system unexpected exception had occurred running the user's - * routine. We get control back within this block. + * routine. We get control back within this block because + * we can't allow the exception out of thread scope. */ - status = PTHREAD_CANCELED; + status = self->exitStatus = PTHREAD_CANCELED; } #else /* __cplusplus */ diff --git a/pthread.h b/pthread.h index 822152c..167adff 100644 --- a/pthread.h +++ b/pthread.h @@ -978,36 +978,38 @@ DWORD _pthread_get_exception_services_code(void); * Redefine the SEH __except keyword to ensure that applications * propagate our internal exceptions up to the library's internal handlers. */ -#define __except(E) \ - __except((GetExceptionCode() == _pthread_get_exception_services_code()) \ - ? EXCEPTION_CONTINUE_SEARCH : (E)) +#define __except( E ) \ + __except( ( GetExceptionCode() == _pthread_get_exception_services_code() ) \ + ? EXCEPTION_CONTINUE_SEARCH : ( E ) ) #endif /* _MSC_VER && ! __cplusplus */ #ifdef __cplusplus -/* FIXME: This is only required if the library was built using C++EH */ - /* * Internal exceptions */ -class Pthread_exception_cancel {}; -class Pthread_exception_exit {}; +class Pthread_exception {}; +class Pthread_exception_cancel : public Pthread_exception {}; +class Pthread_exception_exit : public Pthread_exception {}; /* * Redefine the C++ catch keyword to ensure that applications * propagate our internal exceptions up to the library's internal handlers. */ -#define catch(E) \ - catch(Pthread_exception_cancel) \ - { \ - throw; \ - } \ - catch(Pthread_exception_exit) \ - { \ - throw; \ - } \ - catch(E) +#ifdef _MSC_VER + /* + * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll' + * if you want Pthread-Win32 cancelation and pthread_exit to work. + */ +#define PtW32CatchAll \ + catch( Pthread_exception & ) { throw; } \ + catch( ... ) +#else +#define catch( E ) \ + catch( Pthread_exception & ) { throw; } \ + catch( E ) +#endif #endif diff --git a/sync.c b/sync.c index b7efc29..97decdd 100644 --- a/sync.c +++ b/sync.c @@ -129,11 +129,6 @@ pthread_join (pthread_t thread, void **value_ptr) } else { -#if 0 - DWORD stat; - - stat = WaitForSingleObject (thread->threadH, INFINITE); -#else /* * Pthread_join is a cancelation point. * If we are cancelled then our target thread must not be @@ -142,15 +137,8 @@ pthread_join (pthread_t thread, void **value_ptr) * are cancelled. */ result = pthreadCancelableWait(thread->threadH); -#endif - - if ( -#if 0 - stat == WAIT_OBJECT_0 -#else - result == 0 -#endif - ) + + if (result == 0) { #if ! defined (__MINGW32__) || defined (__MSVCRT__) diff --git a/tests/ChangeLog b/tests/ChangeLog index 902a809..3a18a5b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,63 @@ +2000-08-06 Ross Johnson + + * ccl.bat: Add /nologo to remove extraneous output. + + * exception1.c (exceptionedThread): Init 'dummy'; + put expression into if condition to prevent optimising away; + remove unused variable. + + * cancel4.c (mythread): Cast return value to avoid warnings. + + * cancel2.c (mythread): Missing #endif. + + * condvar9.c (mythread): Cast return value to avoid warnings. + + * condvar8.c (mythread): Cast return value to avoid warnings. + + * condvar7.c (mythread): Cast return value to avoid warnings. + + * cleanup3.c (mythread): Cast return value to avoid warnings. + + * cleanup2.c (mythread): Cast return value to avoid warnings. + + * cleanup1.c (mythread): Cast return value to avoid warnings. + + * condvar5.c (mythread): Cast return value to avoid warnings. + + * condvar3.c (mythread): Cast return value to avoid warnings. + + * condvar6.c (mythread): Cast return value to avoid warnings. + + * condvar4.c (mythread): Cast return value to avoid warnings. + +2000-08-05 Ross Johnson + + * cancel2.c: Use PtW32CatchAll macro if defined. + + * exception1.c: Use PtW32CatchAll macro if defined. + +2000-08-02 Ross Johnson + + * tsd1.c: Fix typecasts of &result [g++ is now very fussy]. + + * test.h (assert): Return 0's explicitly to allay + g++ errors. + + * join2.c: Add explicit typecasts. + + * join1.c: Add explicit typecasts. + + * join0.c: Add explicit typecasts. + + * eyal1.c: Add explicit typecasts. + + * count1.c (main): Add type cast to remove g++ parse warning + [gcc-2.95.2 seems to have tightened up on this]. + + * Makefile (GLANG): Use c++ explicitly. + Remove MSVC sections (was commented out). + Add target to generate cpp output. + 2000-07-25 Ross Johnson * runtest.bat: modified to work under W98. diff --git a/tests/Makefile b/tests/Makefile index 5931855..0775ea3 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,118 +1,112 @@ -# Makefile for the pthreads test suite. -# If all of the .pass files can be created, the test suite has passed. - - -CP = copy -RM = erase -MKDIR = mkdir -TOUCH = echo Passed > -ECHO = @echo - -# -# Mingw32 -# -GLANG = c -CC = gcc -CFLAGS = -g -O2 -UNDEBUG -Wall -x $(GLANG) -o $@ $^ -BUILD_DIR = .. -INCLUDES = -I. -LIBS = -L. -lpthread32 - -## -## MSVC -## -#CC = cl -#CFLAGS = /W3 /MT /nologo /Yd /Zi /Fe$@ $^ -#BUILD_DIR = .. -#INCLUDES = -I. -#LIBS = pthread.lib - -HDR = pthread.h semaphore.h sched.h -LIB = libpthread32.a -DLL = pthread.dll - -COPYFILES = $(HDR) $(LIB) $(DLL) - -# If a test case returns a non-zero exit code to the shell, make will -# stop. - -TESTS = loadfree \ - mutex1 condvar1 condvar2 exit1 create1 equal1 \ - exit2 exit3 \ - join0 join1 join2 mutex2 mutex3 \ - count1 once1 tsd1 self1 self2 cancel1 eyal1 \ - condvar3 condvar4 condvar5 condvar6 condvar7 condvar8 condvar9 \ - errno1 \ - rwlock1 rwlock2 rwlock3 rwlock4 rwlock5 rwlock6 \ - context1 cancel3 cancel4 cleanup1 cleanup2 cleanup3 \ - exception1 - -PASSES = $(TESTS:%=%.pass) - -all: $(PASSES) - @ $(ECHO) ALL TESTS PASSED! Congratulations! - -loadfree.pass: -mutex1.pass: -mutex2.pass: -exit1.pass: -condvar1.pass: -self1.pass: -condvar2.pass: condvar1.pass -create1.pass: mutex2.pass -mutex3.pass: create1.pass -equal1.pass: create1.pass -exit2.pass: create1.pass -exit3.pass: create1.pass -join0.pass: create1.pass -join1.pass: create1.pass -join2.pass: create1.pass -count1.pass: join1.pass -once1.pass: create1.pass -tsd1.pass: join1.pass -self2.pass: create1.pass -eyal1.pass: tsd1.pass -condvar3.pass: create1.pass -condvar4.pass: create1.pass -condvar5.pass: condvar4.pass -condvar6.pass: condvar5.pass -condvar7.pass: condvar6.pass cleanup1.pass -condvar8.pass: condvar7.pass -condvar9.pass: condvar8.pass -errno1.pass: mutex3.pass -rwlock1.pass: condvar6.pass -rwlock2.pass: rwlock1.pass -rwlock3.pass: rwlock2.pass -rwlock4.pass: rwlock3.pass -rwlock5.pass: rwlock4.pass -rwlock6.pass: rwlock5.pass -context1.pass: cancel2.pass -cancel3.pass: context1.pass -cancel4.pass: cancel3.pass -cleanup1.pass: cancel4.pass -cleanup2.pass: cleanup1.pass -cleanup3.pass: cleanup2.pass -exception1.pass: cancel4.pass - -%.pass: %.exe $(LIB) $(DLL) $(HDR) - $* - @ $(ECHO) Passed - @ $(TOUCH) $@ - -%.exe: %.c - @ $(CC) $(CFLAGS) $(INCLUDES) $(LIBS) - -$(COPYFILES): - @ $(ECHO) Copying $@ - @ $(CP) $(BUILD_DIR)\$@ . - -clean: - - $(RM) *.dll - - $(RM) pthread.h - - $(RM) semaphore.h - - $(RM) sched.h - - $(RM) *.a - - $(RM) *.e - - $(RM) *.exe - - $(RM) *.pass - +# Makefile for the pthreads test suite. +# If all of the .pass files can be created, the test suite has passed. + + +CP = copy +RM = erase +MKDIR = mkdir +TOUCH = echo Passed > +ECHO = @echo + +# +# Mingw32 +# +GLANG = c++ +CC = gcc +CFLAGS = -g -O2 -UNDEBUG -Wall -x $(GLANG) +BUILD_DIR = .. +INCLUDES = -I. +LIBS = -L. -lpthread32 + +HDR = pthread.h semaphore.h sched.h +LIB = libpthread32.a +DLL = pthread.dll + +COPYFILES = $(HDR) $(LIB) $(DLL) + +# If a test case returns a non-zero exit code to the shell, make will +# stop. + +TESTS = loadfree \ + mutex1 condvar1 condvar2 exit1 create1 equal1 \ + exit2 exit3 \ + join0 join1 join2 mutex2 mutex3 \ + count1 once1 tsd1 self1 self2 cancel1 eyal1 \ + condvar3 condvar4 condvar5 condvar6 condvar7 condvar8 condvar9 \ + errno1 \ + rwlock1 rwlock2 rwlock3 rwlock4 rwlock5 rwlock6 \ + context1 cancel3 cancel4 cleanup1 cleanup2 cleanup3 \ + exception1 + +PASSES = $(TESTS:%=%.pass) + +all: $(PASSES) + @ $(ECHO) ALL TESTS PASSED! Congratulations! + +loadfree.pass: +mutex1.pass: +mutex2.pass: +exit1.pass: +condvar1.pass: +self1.pass: +condvar2.pass: condvar1.pass +create1.pass: mutex2.pass +mutex3.pass: create1.pass +equal1.pass: create1.pass +exit2.pass: create1.pass +exit3.pass: create1.pass +join0.pass: create1.pass +join1.pass: create1.pass +join2.pass: create1.pass +count1.pass: join1.pass +once1.pass: create1.pass +tsd1.pass: join1.pass +self2.pass: create1.pass +eyal1.pass: tsd1.pass +condvar3.pass: create1.pass +condvar4.pass: create1.pass +condvar5.pass: condvar4.pass +condvar6.pass: condvar5.pass +condvar7.pass: condvar6.pass cleanup1.pass +condvar8.pass: condvar7.pass +condvar9.pass: condvar8.pass +errno1.pass: mutex3.pass +rwlock1.pass: condvar6.pass +rwlock2.pass: rwlock1.pass +rwlock3.pass: rwlock2.pass +rwlock4.pass: rwlock3.pass +rwlock5.pass: rwlock4.pass +rwlock6.pass: rwlock5.pass +context1.pass: cancel2.pass +cancel3.pass: context1.pass +cancel4.pass: cancel3.pass +cleanup1.pass: cancel4.pass +cleanup2.pass: cleanup1.pass +cleanup3.pass: cleanup2.pass +exception1.pass: cancel4.pass + +%.pass: %.exe $(LIB) $(DLL) $(HDR) + $* + @ $(ECHO) Passed + @ $(TOUCH) $@ + +%.exe: %.c + @ $(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) $(LIBS) + +%.pre: %.c + @ $(CC) -E $(CFLAGS) -o $@ $^ $(INCLUDES) + +$(COPYFILES): + @ $(ECHO) Copying $@ + @ $(CP) $(BUILD_DIR)\$@ . + +clean: + - $(RM) *.dll + - $(RM) pthread.h + - $(RM) semaphore.h + - $(RM) sched.h + - $(RM) *.a + - $(RM) *.e + - $(RM) *.exe + - $(RM) *.pass + diff --git a/tests/cancel2.c b/tests/cancel2.c index 44d1b77..b09eab9 100644 --- a/tests/cancel2.c +++ b/tests/cancel2.c @@ -88,7 +88,7 @@ mythread(void * arg) break; } -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) __try #else try @@ -104,10 +104,14 @@ mythread(void * arg) pthread_testcancel(); } } -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__cplusplus) __except(EXCEPTION_EXECUTE_HANDLER) +#else +#if defined(PtW32CatchAll) + PtW32CatchAll #else catch(...) +#endif #endif { /* diff --git a/tests/cancel4.c b/tests/cancel4.c index 59c2f8e..f63241f 100644 --- a/tests/cancel4.c +++ b/tests/cancel4.c @@ -88,7 +88,7 @@ mythread(void * arg) for (bag->count = 0; bag->count < 100; bag->count++) Sleep(100); - return result; + return (void *) result; } int diff --git a/tests/ccl.bat b/tests/ccl.bat index d80ea03..0c42f3d 100644 --- a/tests/ccl.bat +++ b/tests/ccl.bat @@ -5,5 +5,5 @@ REM Generate object file cl /W3 /MT /nologo /Yd /Zi -I. -D_WIN32_WINNT=0x400 -DSTDCALL=_stdcall -c ..\%1.c REM Generate executable -cl /Feaout.exe /Zi %1.obj .\pthread.lib +cl /nologo /Feaout.exe /Zi %1.obj .\pthread.lib del %1.obj > nul: diff --git a/tests/cleanup1.c b/tests/cleanup1.c index 4939e6f..2be711c 100644 --- a/tests/cleanup1.c +++ b/tests/cleanup1.c @@ -98,7 +98,7 @@ mythread(void * arg) pthread_cleanup_pop(0); - return result; + return (void *) result; } int diff --git a/tests/cleanup2.c b/tests/cleanup2.c index c6ca529..515f676 100644 --- a/tests/cleanup2.c +++ b/tests/cleanup2.c @@ -88,7 +88,7 @@ mythread(void * arg) pthread_cleanup_pop(1); - return result; + return (void *) result; } int diff --git a/tests/cleanup3.c b/tests/cleanup3.c index ff84c0b..4f05eea 100644 --- a/tests/cleanup3.c +++ b/tests/cleanup3.c @@ -91,7 +91,7 @@ mythread(void * arg) pthread_cleanup_pop(0); - return result; + return (void *) result; } int diff --git a/tests/condvar3.c b/tests/condvar3.c index deb130a..a25c15a 100644 --- a/tests/condvar3.c +++ b/tests/condvar3.c @@ -67,7 +67,7 @@ mythread(void * arg) assert(pthread_cond_signal(&cv) == 0); - return 0; + return (void *) 0; } int diff --git a/tests/condvar4.c b/tests/condvar4.c index 3feaebb..4729063 100644 --- a/tests/condvar4.c +++ b/tests/condvar4.c @@ -74,7 +74,7 @@ mythread(void * arg) assert(pthread_cond_signal(&cvthing.notbusy) == 0); - return 0; + return (void *) 0; } int diff --git a/tests/condvar5.c b/tests/condvar5.c index d406a2b..d0d15a1 100644 --- a/tests/condvar5.c +++ b/tests/condvar5.c @@ -73,7 +73,7 @@ mythread(void * arg) assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); - return 0; + return (void *) 0; } int diff --git a/tests/condvar6.c b/tests/condvar6.c index 6acc666..7348346 100644 --- a/tests/condvar6.c +++ b/tests/condvar6.c @@ -102,7 +102,7 @@ mythread(void * arg) assert(pthread_mutex_unlock(&cvthing.lock) == 0); - return 0; + return (void *) 0; } int diff --git a/tests/condvar7.c b/tests/condvar7.c index ae51a10..3745f02 100644 --- a/tests/condvar7.c +++ b/tests/condvar7.c @@ -106,7 +106,7 @@ mythread(void * arg) assert(pthread_mutex_unlock(&cvthing.lock) == 0); - return 0; + return (void *) 0; } int diff --git a/tests/condvar8.c b/tests/condvar8.c index 3522546..d1076e3 100644 --- a/tests/condvar8.c +++ b/tests/condvar8.c @@ -110,7 +110,7 @@ mythread(void * arg) assert(pthread_mutex_unlock(&cvthing.lock) == 0); - return 0; + return (void *) 0; } int diff --git a/tests/condvar9.c b/tests/condvar9.c index 9b4f2f8..7d24d09 100644 --- a/tests/condvar9.c +++ b/tests/condvar9.c @@ -111,7 +111,7 @@ mythread(void * arg) assert(pthread_mutex_unlock(&cvthing.lock) == 0); - return 0; + return (void *) 0; } int diff --git a/tests/count1.c b/tests/count1.c index e88a955..ae30ed0 100644 --- a/tests/count1.c +++ b/tests/count1.c @@ -53,7 +53,7 @@ main() /* * Check the number of threads created. */ - assert(numThreads == maxThreads); + assert((int) numThreads == maxThreads); /* * Success. diff --git a/tests/exception1.c b/tests/exception1.c index a7d8e22..eddd8fb 100644 --- a/tests/exception1.c +++ b/tests/exception1.c @@ -56,7 +56,7 @@ exceptionedThread(void * arg) int result = ((int)PTHREAD_CANCELED + 1); int one = 1; int zero = 0; - int dummy; + int dummy = 0; /* Set to async cancelable */ @@ -66,22 +66,32 @@ exceptionedThread(void * arg) Sleep(100); -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(__cplusplus) __try { - dummy = one/zero; + /* Avoid being optimised out */ + if (dummy == one/zero) + Sleep(0); } __except (EXCEPTION_EXECUTE_HANDLER) { + /* Should get into here. */ result = ((int)PTHREAD_CANCELED + 2); } #elif defined(__cplusplus) try { - dummy = one/zero; + /* Avoid being optimised out */ + if (dummy == one/zero) + Sleep(0); } +#if defined(PtW32CatchAll) + PtW32CatchAll +#else catch (...) +#endif { + /* Should get into here. */ result = ((int)PTHREAD_CANCELED + 2); } #endif @@ -93,7 +103,6 @@ void * canceledThread(void * arg) { int result = ((int)PTHREAD_CANCELED + 1); - int dummy; int count; /* Set to async cancelable */ @@ -102,7 +111,7 @@ canceledThread(void * arg) assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(__cplusplus) __try { /* @@ -114,6 +123,7 @@ canceledThread(void * arg) } __except (EXCEPTION_EXECUTE_HANDLER) { + /* Should NOT get into here. */ result = ((int)PTHREAD_CANCELED + 2); } #elif defined(__cplusplus) @@ -126,8 +136,13 @@ canceledThread(void * arg) for (count = 0; count < 100; count++) Sleep(100); } +#if defined(_MSC_VER) + AltCatchAll +#else catch (...) +#endif { + /* Should NOT get into here. */ result = ((int)PTHREAD_CANCELED + 2); } #endif diff --git a/tests/eyal1.c b/tests/eyal1.c index 7a2dc37..849e632 100644 --- a/tests/eyal1.c +++ b/tests/eyal1.c @@ -230,7 +230,7 @@ main (int argc, char *argv[]) { int i; - assert(NULL != (tcs = calloc (nthreads, sizeof (*tcs)))); + assert(NULL != (tcs = (TC *) calloc (nthreads, sizeof (*tcs)))); /* * Launch threads @@ -250,7 +250,8 @@ main (int argc, char *argv[]) assert((tcs[i].stat = pthread_create (&tcs[i].thread, NULL, - (void*)&print_server, (void *)&tcs[i]) + (void*)&print_server, + (void *)&tcs[i]) ) == 0); /* diff --git a/tests/join0.c b/tests/join0.c index cd481ee..54b0bee 100644 --- a/tests/join0.c +++ b/tests/join0.c @@ -26,7 +26,7 @@ main(int argc, char * argv[]) /* Create a single thread and wait for it to exit. */ assert(pthread_create(&id, NULL, func, (void *) 123) == 0); - assert(pthread_join(id, (void *) &result) == 0); + assert(pthread_join(id, (void **) &result) == 0); #if ! defined (__MINGW32__) || defined (__MSVCRT__) assert(result == 123); diff --git a/tests/join1.c b/tests/join1.c index c29e5e6..8cc80e5 100644 --- a/tests/join1.c +++ b/tests/join1.c @@ -37,7 +37,7 @@ main(int argc, char * argv[]) for (i = 0; i < 4; i++) { - assert(pthread_join(id[i], (void *) &result) == 0); + assert(pthread_join(id[i], (void **) &result) == 0); #if ! defined (__MINGW32__) || defined (__MSVCRT__) assert(result == i); #else diff --git a/tests/join2.c b/tests/join2.c index 8b1636c..cdc8ca2 100644 --- a/tests/join2.c +++ b/tests/join2.c @@ -28,7 +28,7 @@ main(int argc, char * argv[]) for (i = 0; i < 4; i++) { - assert(pthread_join(id[i], (void *) &result) == 0); + assert(pthread_join(id[i], (void **) &result) == 0); #if ! defined (__MINGW32__) || defined (__MSVCRT__) /* CRTDLL _beginthread doesn't support return value, so the assertion is guaranteed to fail. */ diff --git a/tests/test.h b/tests/test.h index ffb8180..018b215 100644 --- a/tests/test.h +++ b/tests/test.h @@ -85,9 +85,9 @@ char * error_string[] = { "Assertion succeeded: (%s), file %s, line %d\n", \ #e, __FILE__, (int) __LINE__), \ fflush(stderr) : \ - (void) 0) : \ + 0) : \ (fprintf(stderr, "Assertion failed: (%s), file %s, line %d\n", \ - #e, __FILE__, (int) __LINE__), exit(1))) + #e, __FILE__, (int) __LINE__), exit(1), 0)) #endif /* NDEBUG */ diff --git a/tests/tsd1.c b/tests/tsd1.c index 9926a30..a65cf66 100644 --- a/tests/tsd1.c +++ b/tests/tsd1.c @@ -142,7 +142,7 @@ main() { int result = 0; - assert(pthread_join(thread[i], (void *) &result) == 0); + assert(pthread_join(thread[i], (void **) &result) == 0); } assert(pthread_key_delete(key) == 0); -- cgit v1.2.3