pthread_pause pthread_unpause
[mirrors/Programs.git] / c / pthread_extra / test.c
index a41ca54a0023cdcfc714f18540d5fc9fe30ec4da..f39a979cb7ade2f6acc46ce9e1e79f4042967103 100644 (file)
@@ -17,7 +17,7 @@ int main_mumu() {
        //Set timeout
        struct  timespec tm;
        clock_gettime(CLOCK_REALTIME, &tm);
-       tm.tv_sec  += 5;
+       tm.tv_sec  += 2;
 
        //Lock one of the locks for testing
        pthread_mutex_lock(lck[2]);
@@ -29,29 +29,43 @@ int main_mumu() {
                printf("FAILED!\n");
        }
 
+       return 0;
 }
 
 
 pthread_mq_t myq;
 
-void *thread_recv(void *args) {
+void *thread_recv() {
+       //(void *)args;
+
        char str[128];
        while(1) {
-               pthread_mq_receive_generic(&myq, &str, false, PTHREAD_XTIME_FOREVER);
-               printf("RECVD: %.6s\t\t(waiting %d)\n", str, pthread_mq_waiting(&myq));
-               //sleep(1);
+               if(pthread_mq_receive_generic(&myq, &str, false, PTHREAD_XTIME_FOREVER))
+                       printf("-RECVD: %.6s\t\t(waiting %d)\n", str, (int)pthread_mq_waiting(&myq));
+               if(pthread_mq_receive_generic(&myq, &str, false, PTHREAD_XTIME_NOBLOCK))
+                       printf("+RECVD: %.6s\t\t(waiting %d)\n", str, (int)pthread_mq_waiting(&myq));
+       }
+}
+
+void *thread_send() {
+       while(1) {
+               pthread_mq_send_generic(&myq, " X   ", true, PTHREAD_XTIME_NOBLOCK);
+               pthread_mq_send_generic(&myq, " Y   ", false, PTHREAD_XTIME_FOREVER);
        }
 }
 
+
 int main() {
-       main_mumu();
+       //main_mumu();
 
-       char tmp[128];
+       //char tmp[128];
 
        pthread_mq_init(&myq, 6, 5);
 
        pthread_t t;
        pthread_create(&t, NULL, thread_recv, NULL);
+       pthread_t s;
+       pthread_create(&s, NULL, thread_send, NULL);
 
        pthread_mq_send_generic(&myq, "AHOJ1", false, NULL);
        pthread_mq_send_generic(&myq, "AHOJ2", false, NULL);
@@ -61,11 +75,10 @@ int main() {
        pthread_mq_send_generic(&myq, "AHOJ6", true, NULL);
 
        while(1) {
-               pthread_mq_send_generic(&myq, "B", false, NULL);
-               pthread_mq_send_generic(&myq, "A", true, NULL);
-               pthread_mq_send_generic(&myq, " A", false, NULL);
-               pthread_mq_send_generic(&myq, " B", false, NULL);
-               sleep(1);
+               pthread_mq_send_generic(&myq, "B    ", false, NULL);
+               pthread_mq_send_generic(&myq, "A    ", true, NULL);
+               pthread_mq_send_generic(&myq, " B   ", false, PTHREAD_XTIME_FOREVER);
+               pthread_mq_send_generic(&myq, " A   ", false, PTHREAD_XTIME_NOBLOCK);
        }
 
        pthread_join(t, NULL);
This page took 0.108046 seconds and 4 git commands to generate.