From 52f7c3f5ef6d9b70ec385fb390bf27962e68ee3d Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 8 Mar 1999 21:02:20 +0000 Subject: Resolve merge conflicts; minor comment changes. --- ChangeLog | 4 ++ FAQ | 4 +- README | 4 +- implement.h | 2 +- tests/Makefile | 140 ++++++++++++++++++++++---------------------- tests/Template.c | 34 ++++++----- tests/condvar2.c | 165 ++++++++++++++++++++++++++-------------------------- tests/tryentercs.c | 70 ++++++++++++++++++++++ tests/tryentercs2.c | 59 +++++++++++++++++++ 9 files changed, 310 insertions(+), 172 deletions(-) create mode 100644 tests/tryentercs.c create mode 100644 tests/tryentercs2.c diff --git a/ChangeLog b/ChangeLog index 5f50d64..ebf4fa2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -44,6 +44,10 @@ Sun Mar 7 12:31:14 1999 Ross Johnson (pthread_cond_t): no longer a pointer to pthread_cond_t_. (pthread_cond_t_): add 'staticinit' and 'valid' elements. +Sat Mar 6 1999 Ross Johnson + + * implement.h: Undate comments. + Sun Feb 21 1999 Ross Johnson * pthread.h (PTHREAD_MUTEX_INITIALIZER): missing braces around diff --git a/FAQ b/FAQ index d4665e3..da9cd75 100644 --- a/FAQ +++ b/FAQ @@ -5,14 +5,14 @@ INDEX ----- -Q 1 How do I get pthreads-win32 to link under Cygwin32 or Mingw32? +Q 1 How do I get pthreads-win32 to link under Cygwin or Mingw32? Q 2 Now that pthreads-win32 builds under Mingw32, why do I get memory access violations? ============================================================================= -Q 1 How do I get pthreads-win32 to link under Cygwin32 or Mingw32? +Q 1 How do I get pthreads-win32 to link under Cygwin or Mingw32? --- A 1 diff --git a/README b/README index 24019a2..e83ca98 100644 --- a/README +++ b/README @@ -10,7 +10,7 @@ and place the fllowing text in the message body: subscribe pthreads-win32 -Building the library with Cygwin32 or Mingw32 +Building the library with Cygwin or Mingw32 --------------------------------------------- Feb 18, 1999 @@ -25,7 +25,7 @@ exception handling in g++. Thanks to Kevin Ruland for researching this one. See the FAQ Question 2 for more information. However, you can use the export library libpthread32.a built under -Mingw32 (not tested under Cygwin32) together with the pthread.dll built +Mingw32 (not tested under Cygwin) together with the pthread.dll built with MSVC. Thanks to Anders Norlander for pointing this out. For convenience, the following pre-built files can be downloaded from diff --git a/implement.h b/implement.h index 4ee33a6..6b7ae7a 100644 --- a/implement.h +++ b/implement.h @@ -208,7 +208,7 @@ int _pthread_sem_post (_pthread_sem_t * sem); /* * Check for old and new versions of cygwin. See the FAQ file: * - * Question 1 - How do I get pthreads-win32 to link under Cygwin32 or Mingw32? + * Question 1 - How do I get pthreads-win32 to link under Cygwin or Mingw32? * * Patch by Anders Norlander */ diff --git a/tests/Makefile b/tests/Makefile index dcbb7e0..e5994f6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,70 +1,70 @@ -# 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 -# -CC = gcc -CFLAGS = -g -O2 -UNDEBUG -Wall -o $@ $^ -BUILD_DIR = .. -INCLUDES = -I. -LIBS = ./libpthread32.a - -## -## MSVC -## -#CC = cl -#CFLAGS = /W3 /MT /nologo /Yd /Zi /Fe$@ $^ -#BUILD_DIR = .. -#INCLUDES = -I. -#LIBS = pthread.lib - -HDR = pthread.h -LIB = libpthread32.a -DLL = pthread.dll - -# If a test case returns a non-zero exit code to the shell, make will -# stop. - -TESTS = count1 create1 equal1 exit1 exit2 exit3 \ - join1 mutex1 mutex2 mutex3 \ - once1 self1 self2 condvar1 condvar2 condvar3 condvar4 tsd1 - -PASSES = $(TESTS:%=%.pass) - -all: $(PASSES) - @ $(ECHO) ALL TESTS PASSED! Congratulations! - -%.pass: %.exe $(LIB) $(DLL) $(HDR) - $* - @$(ECHO) Passed - @ $(TOUCH) $@ - -%.exe: %.c - @ $(CC) $(CFLAGS) $(INCLUDES) $(LIBS) - -$(LIB): - @ $(ECHO) Copying the library - @ $(CP) $(BUILD_DIR)\$@ . - -$(HDR): - @ $(ECHO) Copying the header file - @ $(CP) $(BUILD_DIR)\$@ . - -$(DLL): - @ $(ECHO) Copying the DLL - @ $(CP) $(BUILD_DIR)\$@ . - -clean: - - $(RM) *.dll - - $(RM) $(LIB) - - $(RM) $(HDR) - - $(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 +# +CC = gcc +CFLAGS = -g -O2 -UNDEBUG -Wall -o $@ $^ +BUILD_DIR = .. +INCLUDES = -I. +LIBS = ./libpthread32.a + +## +## MSVC +## +#CC = cl +#CFLAGS = /W3 /MT /nologo /Yd /Zi /Fe$@ $^ +#BUILD_DIR = .. +#INCLUDES = -I. +#LIBS = pthread.lib + +HDR = pthread.h +LIB = libpthread32.a +DLL = pthread.dll + +# If a test case returns a non-zero exit code to the shell, make will +# stop. + +TESTS = count1 create1 equal1 exit1 exit2 exit3 \ + join1 mutex1 mutex2 mutex3 \ + once1 self1 self2 condvar1 condvar2 condvar3 condvar4 tsd1 + +PASSES = $(TESTS:%=%.pass) + +all: $(PASSES) + @ $(ECHO) ALL TESTS PASSED! Congratulations! + +%.pass: %.exe $(LIB) $(DLL) $(HDR) + $* + @$(ECHO) Passed + @ $(TOUCH) $@ + +%.exe: %.c + @ $(CC) $(CFLAGS) $(INCLUDES) $(LIBS) + +$(LIB): + @ $(ECHO) Copying the library + @ $(CP) $(BUILD_DIR)\$@ . + +$(HDR): + @ $(ECHO) Copying the header file + @ $(CP) $(BUILD_DIR)\$@ . + +$(DLL): + @ $(ECHO) Copying the DLL + @ $(CP) $(BUILD_DIR)\$@ . + +clean: + - $(RM) *.dll + - $(RM) $(LIB) + - $(RM) $(HDR) + - $(RM) *.exe + - $(RM) *.pass diff --git a/tests/Template.c b/tests/Template.c index 0663a85..c98bbac 100644 --- a/tests/Template.c +++ b/tests/Template.c @@ -44,18 +44,18 @@ /* * Create NUMTHREADS threads in addition to the Main thread. */ -static enum { +enum { NUMTHREADS = 2 }; typedef struct bag_t_ bag_t; struct bag_t_ { int threadnum; - int washere; - /* Add more pre-thread state variables here */ + int started; + /* Add more per-thread state variables here */ }; -static bag_t threadbag[NUMTHREADS]; +static bag_t threadbag[NUMTHREADS + 1]; void * mythread(void * arg) @@ -63,8 +63,8 @@ mythread(void * arg) bag_t * bag = (bag_t *) arg; assert(bag == &threadbag[bag->threadnum]); - assert(bag->washere == 0); - bag->washere = 1; + assert(bag->started == 0); + bag->started = 1; /* ... */ @@ -80,12 +80,17 @@ main() assert((t[0] = pthread_self()) != NULL); for (i = 1; i <= NUMTHREADS; i++) - { - threadbag[i].washere = 0; + { + threadbag[i].started = 0; threadbag[i].threadnum = i; assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); } + /* + * Code to control or munipulate child threads should probably go here. + */ + + /* * Give threads time to run. */ @@ -96,24 +101,25 @@ main() */ for (i = 1; i <= NUMTHREADS; i++) { - if (threadbag[i].washere != 1) + failed = !threadbag[i].started; + + if (failed) { - failed = 1; - fprintf(stderr, "Thread %d: washere %d\n", i, threadbag[i].washere); + fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started); } } - assert(failed == 0); + assert(!failed); /* - * Check any results here. Only print ouput and set "failed" on failure. + * Check any results here. Set "failed" and only print ouput on failure. */ for (i = 1; i <= NUMTHREADS; i++) { /* ... */ } - assert(failed == 0); + assert(!failed); /* * Success. diff --git a/tests/condvar2.c b/tests/condvar2.c index 66f3d7b..09e4576 100644 --- a/tests/condvar2.c +++ b/tests/condvar2.c @@ -1,83 +1,82 @@ -/* - * File: condvar1.c - * - * Test Synopsis: - * - Test timed wait on a CV. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Because the CV is never signaled, we expect the wait to time out. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - pthread_cond_timedwait returns ETIMEDOUT. - * - Process returns zero exit status. - * - * Fail Criteria: - * - pthread_cond_timedwait does not return ETIMEDOUT. - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -pthread_cond_t cv; -pthread_mutex_t mutex; - -int -main() -{ - struct timespec abstime = { 0, 0 }; -#if defined(__MINGW32__) - struct timeb currSysTime; -#else - struct _timeb currSysTime; -#endif - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - assert(pthread_cond_init(&cv, NULL) == 0); - - assert(pthread_mutex_init(&mutex, NULL) == 0); - - assert(pthread_mutex_lock(&mutex) == 0); - - /* get current system time */ - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == ETIMEDOUT); - - assert(pthread_mutex_unlock(&mutex) == 0); - - assert(pthread_cond_destroy(&cv) == 0); - - return 0; -} - +/* + * File: condvar1.c + * + * Test Synopsis: + * - Test timed wait on a CV. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Because the CV is never signaled, we expect the wait to time out. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait does not return ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +pthread_cond_t cv; +pthread_mutex_t mutex; + +int +main() +{ + struct timespec abstime = { 0, 0 }; +#if defined(__MINGW32__) + struct timeb currSysTime; +#else + struct _timeb currSysTime; +#endif + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert(pthread_cond_init(&cv, NULL) == 0); + + assert(pthread_mutex_init(&mutex, NULL) == 0); + + assert(pthread_mutex_lock(&mutex) == 0); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == ETIMEDOUT); + + assert(pthread_mutex_unlock(&mutex) == 0); + + assert(pthread_cond_destroy(&cv) == 0); + + return 0; +} diff --git a/tests/tryentercs.c b/tests/tryentercs.c new file mode 100644 index 0000000..1125611 --- /dev/null +++ b/tests/tryentercs.c @@ -0,0 +1,70 @@ +/* + * tryentercs.c + * + * See if we have the TryEnterCriticalSection function. + * Does not use any part of pthreads. + */ + +#include +#include +#include + +/* + * Function pointer to TryEnterCriticalSection if it exists + * - otherwise NULL + */ +BOOL (WINAPI *_try_enter_critical_section)(LPCRITICAL_SECTION) = +NULL; + +/* + * Handle to kernel32.dll + */ +static HINSTANCE _h_kernel32; + + +int +main() +{ + CRITICAL_SECTION cs; + + SetLastError(0); + + printf("Last Error [main enter] %ld\n", (long) GetLastError()); + + /* + * Load KERNEL32 and try to get address of TryEnterCriticalSection + */ + _h_kernel32 = LoadLibrary(TEXT("KERNEL32.DLL")); + _try_enter_critical_section = + (BOOL (PT_STDCALL *)(LPCRITICAL_SECTION)) + GetProcAddress(_h_kernel32, + (LPCSTR) "TryEnterCriticalSection"); + + if (_try_enter_critical_section != NULL) + { + InitializeCriticalSection(&cs); + + SetLastError(0); + + if ((*_try_enter_critical_section)(&cs) != 0) + { + LeaveCriticalSection(&cs); + } + else + { + printf("Last Error [try enter] %ld\n", (long) GetLastError()); + + _try_enter_critical_section = NULL; + } + DeleteCriticalSection(&cs); + } + + (void) FreeLibrary(_h_kernel32); + + printf("This system %s TryEnterCriticalSection.\n", + (_try_enter_critical_section == NULL) ? "DOES NOT SUPPORT" : "SUPPORTS"); + printf("POSIX Mutexes will be based on Win32 %s.\n", + (_try_enter_critical_section == NULL) ? "Mutexes" : "Critical Sections"); + + return(0); +} \ No newline at end of file diff --git a/tests/tryentercs2.c b/tests/tryentercs2.c new file mode 100644 index 0000000..adce6df --- /dev/null +++ b/tests/tryentercs2.c @@ -0,0 +1,59 @@ +/* + * tryentercs.c + * + * See if we have the TryEnterCriticalSection function. + * Does not use any part of pthreads. + */ + +#include +#include +#include + +/* + * Function pointer to TryEnterCriticalSection if it exists + * - otherwise NULL + */ +BOOL (WINAPI *_try_enter_critical_section)(LPCRITICAL_SECTION) = NULL; + +/* + * Handle to kernel32.dll + */ +static HINSTANCE _h_kernel32; + + +int +main() +{ + LPCRITICAL_SECTION lpcs = NULL; + + SetLastError(0); + + printf("Last Error [main enter] %ld\n", (long) GetLastError()); + + /* + * Load KERNEL32 and try to get address of TryEnterCriticalSection + */ + _h_kernel32 = LoadLibrary(TEXT("KERNEL32.DLL")); + _try_enter_critical_section = + (BOOL (PT_STDCALL *)(LPCRITICAL_SECTION)) + GetProcAddress(_h_kernel32, + (LPCSTR) "TryEnterCriticalSection"); + + if (_try_enter_critical_section != NULL) + { + SetLastError(0); + + (*_try_enter_critical_section)(lpcs); + + printf("Last Error [try enter] %ld\n", (long) GetLastError()); + } + + (void) FreeLibrary(_h_kernel32); + + printf("This system %s TryEnterCriticalSection.\n", + (_try_enter_critical_section == NULL) ? "DOES NOT SUPPORT" : "SUPPORTS"); + printf("POSIX Mutexes will be based on Win32 %s.\n", + (_try_enter_critical_section == NULL) ? "Mutexes" : "Critical Sections"); + + return(0); +} \ No newline at end of file -- cgit v1.2.3