summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/thread/descriptor.pgc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/test/thread/descriptor.pgc')
-rw-r--r--src/interfaces/ecpg/test/thread/descriptor.pgc68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/thread/descriptor.pgc b/src/interfaces/ecpg/test/thread/descriptor.pgc
new file mode 100644
index 0000000..76a7a5d
--- /dev/null
+++ b/src/interfaces/ecpg/test/thread/descriptor.pgc
@@ -0,0 +1,68 @@
+#ifdef ENABLE_THREAD_SAFETY
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <process.h>
+#include <locale.h>
+#else
+#include <pthread.h>
+#endif
+#endif
+#include <stdio.h>
+
+#define THREADS 16
+#define REPEATS 50000
+
+EXEC SQL include sqlca;
+EXEC SQL whenever sqlerror sqlprint;
+EXEC SQL whenever not found sqlprint;
+
+#if defined(ENABLE_THREAD_SAFETY) && defined(WIN32)
+static unsigned __stdcall fn(void* arg)
+#else
+static void* fn(void* arg)
+#endif
+{
+ int i;
+
+ for (i = 1; i <= REPEATS; ++i)
+ {
+ EXEC SQL ALLOCATE DESCRIPTOR mydesc;
+ EXEC SQL DEALLOCATE DESCRIPTOR mydesc;
+ }
+
+ return 0;
+}
+
+int main ()
+{
+#ifdef ENABLE_THREAD_SAFETY
+ int i;
+#ifdef WIN32
+ HANDLE threads[THREADS];
+#else
+ pthread_t threads[THREADS];
+#endif
+
+#ifdef WIN32
+ for (i = 0; i < THREADS; ++i)
+ {
+ unsigned id;
+ threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, NULL, 0, &id);
+ }
+
+ WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
+ for (i = 0; i < THREADS; ++i)
+ CloseHandle(threads[i]);
+#else
+ for (i = 0; i < THREADS; ++i)
+ pthread_create(&threads[i], NULL, fn, NULL);
+ for (i = 0; i < THREADS; ++i)
+ pthread_join(threads[i], NULL);
+#endif
+#else
+ fn(NULL);
+#endif
+
+ return 0;
+}