- pthread_t child_thread[2];
- int id1 = 1;
- int id2 = 2;
- pthread_create(&child_thread[0], 0 /* attr */, run_func, &id1);
- pthread_create(&child_thread[1], 0 /* attr */, run_func, &id2);
- pthread_join(child_thread[0], 0);
- pthread_join(child_thread[1], 0);
+#ifdef WIN32
+ HANDLE handles[NUM_THREADS];
+ DWORD dwThreadId[NUM_THREADS];
+#endif
+#if YAZ_POSIX_THREADS
+ pthread_t child_thread[NUM_THREADS];
+#endif
+ int i, id[NUM_THREADS];
+
+ seqp = seq;
+ assert (num <= NUM_THREADS);
+ for (i = 0; i < num; i++)
+ {
+ id[i] = write_flag;
+#if YAZ_POSIX_THREADS
+ pthread_create(&child_thread[i], 0 /* attr */, run_func, &id[i]);
+#endif
+#ifdef WIN32
+ if (1)
+ {
+ void *pData = &id[i];
+ handles[i] = CreateThread(
+ NULL, /* default security attributes */
+ 0, /* use default stack size */
+ ThreadProc, /* thread function */
+ pData, /* argument to thread function */
+ 0, /* use default creation flags */
+ &dwThreadId[i]); /* returns the thread identifier */
+ }
+
+#endif
+ }
+#if YAZ_POSIX_THREADS
+ for (i = 0; i<num; i++)
+ pthread_join(child_thread[i], 0);
+#endif
+#ifdef WIN32
+ WaitForMultipleObjects(num, handles, TRUE, INFINITE);
+#endif
+ for (i = 0; i < num; i++)
+ YAZ_CHECK(id[i] == 123);