1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
12 #include <yaz/mutex.h>
13 #include <yaz/thread_create.h>
23 #include <yaz/gettimeofday.h>
25 static void tst_mutex(void)
33 yaz_mutex_destroy(&p);
38 yaz_mutex_set_name(p, YLOG_LOG, "mymutex");
41 yaz_mutex_destroy(&p);
44 yaz_mutex_destroy(&p); /* OK to "destroy" NULL handle */
47 static void tst_cond(void)
51 struct timeval abstime;
62 r = yaz_gettimeofday(&abstime);
65 abstime.tv_sec += 1; /* wait 1 second */
67 r = yaz_cond_wait(c, p, &abstime);
73 yaz_mutex_destroy(&p);
77 static void *my_handler(void *arg)
79 int *mydata = (int*) arg;
84 static void tst_create_thread(void)
91 t[0] = yaz_thread_create(my_handler, &mydata0);
93 t[1] = yaz_thread_create(my_handler, &mydata1);
97 yaz_thread_join(&t[0], &return_data);
99 YAZ_CHECK(return_data == &mydata0);
102 yaz_thread_join(&t[1], &return_data);
104 YAZ_CHECK(return_data == &mydata1);
106 YAZ_CHECK_EQ(mydata0, 43);
107 YAZ_CHECK_EQ(mydata1, 43);
110 int main (int argc, char **argv)
112 YAZ_CHECK_INIT(argc, argv);
123 * c-file-style: "Stroustrup"
124 * indent-tabs-mode: nil
126 * vim: shiftwidth=4 tabstop=8 expandtab