2 * Copyright (C) 1995-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstflock.c,v 1.8 2006-06-27 12:24:14 adam Exp $
18 #include <idzebra/flock.h>
25 static char *seqp = seq;
29 static void small_sleep()
38 void *run_func(void *arg)
41 int *pdata = (int*) arg;
42 int use_write_lock = *pdata;
43 ZebraLockHandle lh = zebra_lock_create(0, "my.LCK");
67 zebra_lock_destroy(lh);
73 DWORD WINAPI ThreadProc(void *p)
79 static void tst_win32(int num)
81 HANDLE handles[NUM_THREADS];
82 DWORD dwThreadId[NUM_THREADS];
83 int i, id[NUM_THREADS];
85 assert (num <= NUM_THREADS);
86 for (i = 0; i<num; i++)
89 id[i] = i >= 2 ? 0 : 1; /* first two are writing.. rest is reading */
90 handles[i] = CreateThread(
91 NULL, /* default security attributes */
92 0, /* use default stack size */
93 ThreadProc, /* thread function */
94 pData, /* argument to thread function */
95 0, /* use default creation flags */
96 &dwThreadId[i]); /* returns the thread identifier */
99 WaitForMultipleObjects(num, handles, TRUE, INFINITE);
103 #if YAZ_POSIX_THREADS
104 static void tst_pthread(int num)
106 pthread_t child_thread[NUM_THREADS];
107 int i, id[NUM_THREADS];
109 assert (num <= NUM_THREADS);
110 for (i = 0; i<num; i++)
112 id[i] = i >= 2 ? 0 : 1; /* first two are writing.. rest is reading */
113 pthread_create(&child_thread[i], 0 /* attr */, run_func, &id[i]);
116 for (i = 0; i<num; i++)
117 pthread_join(child_thread[i], 0);
119 for (i = 0; i<num; i++)
120 YAZ_CHECK(id[i] == 123);
124 int main(int argc, char **argv)
126 YAZ_CHECK_INIT(argc, argv);
132 #if YAZ_POSIX_THREADS
138 printf("seq=%s\n", seq);
141 /* does not pass.. for bug 529 */
142 YAZ_CHECK(strcmp(seq, "LULULULU") == 0); /* for tst_pthread when num=2 */
151 * indent-tabs-mode: nil
153 * vim: shiftwidth=4 tabstop=8 expandtab