diff options
Diffstat (limited to 'src/interfaces/ecpg/test/thread')
-rw-r--r-- | src/interfaces/ecpg/test/thread/thread.pgc | 18 | ||||
-rw-r--r-- | src/interfaces/ecpg/test/thread/thread_implicit.pgc | 18 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/interfaces/ecpg/test/thread/thread.pgc b/src/interfaces/ecpg/test/thread/thread.pgc index e7f0b4d1dca..726121d2ca2 100644 --- a/src/interfaces/ecpg/test/thread/thread.pgc +++ b/src/interfaces/ecpg/test/thread/thread.pgc @@ -13,7 +13,11 @@ main(void) return 0; } #else +#ifndef WIN32 #include <pthread.h> +#else +#include <windows.h> +#endif exec sql include ../regression; @@ -24,7 +28,11 @@ int iterations = 20; int main(int argc, char *argv[]) { +#ifndef WIN32 pthread_t *threads; +#else + HANDLE *threads; +#endif int n; EXEC SQL BEGIN DECLARE SECTION; int l_rows; @@ -47,7 +55,7 @@ int main(int argc, char *argv[]) EXEC SQL DISCONNECT; /* create, and start, threads */ - threads = calloc(nthreads, sizeof(pthread_t)); + threads = calloc(nthreads, sizeof(threads[0])); if( threads == NULL ) { fprintf(stderr, "Cannot alloc memory\n"); @@ -55,14 +63,22 @@ int main(int argc, char *argv[]) } for( n = 0; n < nthreads; n++ ) { +#ifndef WIN32 pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1)); +#else + threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_thread, (void *) (n + 1), 0, NULL); +#endif } /* wait for thread completion */ +#ifndef WIN32 for( n = 0; n < nthreads; n++ ) { pthread_join(threads[n], NULL); } +#else + WaitForMultipleObjects(nthreads, threads, TRUE, INFINITE); +#endif free(threads); /* and check results */ diff --git a/src/interfaces/ecpg/test/thread/thread_implicit.pgc b/src/interfaces/ecpg/test/thread/thread_implicit.pgc index e4033849600..010a8e52051 100644 --- a/src/interfaces/ecpg/test/thread/thread_implicit.pgc +++ b/src/interfaces/ecpg/test/thread/thread_implicit.pgc @@ -14,7 +14,11 @@ main(void) return 0; } #else +#ifndef WIN32 #include <pthread.h> +#else +#include <windows.h> +#endif exec sql include ../regression; @@ -25,7 +29,11 @@ int iterations = 20; int main(int argc, char *argv[]) { +#ifndef WIN32 pthread_t *threads; +#else + HANDLE *threads; +#endif int n; EXEC SQL BEGIN DECLARE SECTION; int l_rows; @@ -48,7 +56,7 @@ int main(int argc, char *argv[]) EXEC SQL DISCONNECT; /* create, and start, threads */ - threads = calloc(nthreads, sizeof(pthread_t)); + threads = calloc(nthreads, sizeof(threads[0])); if( threads == NULL ) { fprintf(stderr, "Cannot alloc memory\n"); @@ -56,14 +64,22 @@ int main(int argc, char *argv[]) } for( n = 0; n < nthreads; n++ ) { +#ifndef WIN32 pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1)); +#else + threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_thread, (void *) (n+1), 0, NULL); +#endif } /* wait for thread completion */ +#ifndef WIN32 for( n = 0; n < nthreads; n++ ) { pthread_join(threads[n], NULL); } +#else + WaitForMultipleObjects(nthreads, threads, TRUE, INFINITE); +#endif free(threads); /* and check results */ |