2 #include <pthread_extra.h>
10 //Prepare mutex array for tests
11 static pthread_mutex_t la
= PTHREAD_MUTEX_INITIALIZER
;
12 static pthread_mutex_t lb
= PTHREAD_MUTEX_INITIALIZER
;
13 static pthread_mutex_t lc
= PTHREAD_MUTEX_INITIALIZER
;
14 static pthread_mutex_t ld
= PTHREAD_MUTEX_INITIALIZER
;
15 static pthread_mutex_t
*lck
[4] = {&la
, &lb
, &lc
, &ld
};
19 clock_gettime(CLOCK_REALTIME
, &tm
);
22 //Lock one of the locks for testing
23 pthread_mutex_lock(lck
[2]);
25 if(!pthread_mutex_timedlock_multi(lck
, 4, &tm
)) {
26 //if(!pthread_mutex_timedlock_two(&la, lck[2], &tm)) {
37 void *thread_recv(void *args
) {
40 pthread_mq_receive_generic(&myq
, &str
, false, PTHREAD_XTIME_FOREVER
);
41 printf("RECVD: %.6s\t\t(waiting %d)\n", str
, pthread_mq_waiting(&myq
));
51 pthread_mq_init(&myq
, 6, 5);
54 pthread_create(&t
, NULL
, thread_recv
, NULL
);
56 pthread_mq_send_generic(&myq
, "AHOJ1", false, NULL
);
57 pthread_mq_send_generic(&myq
, "AHOJ2", false, NULL
);
58 pthread_mq_send_generic(&myq
, "AHOJ3", true, NULL
);
59 pthread_mq_send_generic(&myq
, "AHOJ4", true, NULL
);
60 pthread_mq_send_generic(&myq
, "AHOJ5", false, NULL
);
61 pthread_mq_send_generic(&myq
, "AHOJ6", true, NULL
);
64 pthread_mq_send_generic(&myq
, "B", false, NULL
);
65 pthread_mq_send_generic(&myq
, "A", true, NULL
);
66 pthread_mq_send_generic(&myq
, " A", false, NULL
);
67 pthread_mq_send_generic(&myq
, " B", false, NULL
);
71 pthread_join(t
, NULL
);