Fixed deadlocks in pthread_pause
authorTomas Mudrunka <tomas@mudrunka.cz>
Tue, 29 Jun 2021 11:15:11 +0000 (13:15 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Tue, 29 Jun 2021 11:15:11 +0000 (13:15 +0200)
c/pthread_extra/Makefile
c/pthread_extra/README.md
c/pthread_extra/pthread_pause.c
c/pthread_extra/test_pause.c

index 0b96b41a16e61e1a4b29348345f8afd847f4a6cd..1197cca9d85dcaa98a655dba50a5528a4fa8feb4 100644 (file)
@@ -1,5 +1,5 @@
 COPT=-g -O2 -flto -ftree-vectorize -ftree-slp-vectorize -fvisibility=hidden -D_FORTIFY_SOURCE=2 -DMG_ENABLE_FS=0 -fstack-protector-strong -fno-delete-null-pointer-checks $(CARCH)\r
-#COPT=-fvisibility=hidden -DMG_ENABLE_FS=0 -fstack-protector-strong $(CARCH)\r
+#COPT=-g -fvisibility=hidden -DMG_ENABLE_FS=0 -fstack-protector-strong $(CARCH)\r
 CDEF=-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE=1 -D_GNU_SOURCE\r
 CERR=-Wall -Wextra -Werror -pedantic -Werror=date-time -Wformat-security -Wduplicated-cond -Wfloat-equal -Wshadow -Wlogical-not-parentheses -Wnull-dereference\r
 \r
index 0824f473a1fd381749202eaa8c58c6bf10e09e9c..60876f2cec9dc1aed8d94392599d78f693375a96 100644 (file)
@@ -5,7 +5,7 @@ Currently will probably only work on Linux. Mostly experimental code.
 
 ### Components
 
+  * pthread_pause - implements suspend/resume functionality for pthreads (no know issues, recently fixed some deadlocks, but not really tested)
   * pthread_msgqueue - implements message queues, more features than POSIX mqueue (no known issues, but not really tested)
   * pthread_user_data - allows user to store and retreive custom data using thread handle as a key (suboptimal, used internaly, not tested)
-  * pthread_multi - lock multiple mutexes at once (might cause deadlocks in complex scenarios)
-  * pthread_pause - implements suspend/resume functionality for pthreads (causes deadlocks under high load)
+  * pthread_multi - lock multiple mutexes at once (might cause deadlocks in complex scenarios???)
index 662d78fdd99a949e041a15c093f862c01d1f5a5d..6df2e3a83c5f51bedecc93b2cde41ed615d3bc08 100644 (file)
@@ -19,7 +19,7 @@ void pthread_pause_handler() {
        sigset_t sigset;
        sigfillset(&sigset);
        sigdelset(&sigset, PTHREAD_XSIG_STOP);
-       while(!pthread_user_data_internal(pthread_self())->running) {
+       if(!pthread_user_data_internal(pthread_self())->running) {
                sigsuspend(&sigset);
        }
 }
index 47f2db0cc20b0cf48bb17284cd1fab5891673676..467328940c87c786f61b024436de2506a4fa8dc6 100644 (file)
@@ -22,6 +22,22 @@ int main() {
        //That way you can be sure it is pausable immediately
        pthread_create(&a, NULL, thread_test, " A");
        pthread_create(&b, NULL, thread_test, " B");
+       //sleep(1);
+
+       //printf("OK\n");
+       /*
+       for(int32_t i = 1;i>0;i++) {
+               pthread_pause(a);
+               pthread_pause(a);
+               pthread_unpause(a);
+               pthread_unpause(a);
+       }
+       */
+       /*
+       exit(23);
+       pthread_pause(a);
+       pthread_unpause(b);
+       */
 
        while(1) {
                pthread_pause(b);
This page took 0.226642 seconds and 4 git commands to generate.