[Bug 1131330] New: pthread_mutex_destroy occasionally returns EBUSY even though mutex is unlocked
http://bugzilla.opensuse.org/show_bug.cgi?id=1131330 Bug ID: 1131330 Summary: pthread_mutex_destroy occasionally returns EBUSY even though mutex is unlocked Classification: openSUSE Product: openSUSE Distribution Version: Leap 15.0 Hardware: x86-64 OS: SUSE Other Status: NEW Severity: Normal Priority: P5 - None Component: Basesystem Assignee: bnc-team-screening@forge.provo.novell.com Reporter: asbeer@gmail.com QA Contact: qa-bugs@suse.de Found By: --- Blocker: --- User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36 Build Identifier: I'm running the latest patched/updated OpenSUSE LEAP 15.0. My glibc version is 2.26-lp150.11.9.1. When I compile and run the following program on my system and let it run for a while (normally less than 30 seconds) it exits indicating that pthread_mutex_destroy() returned 16 (EBUSY). However, it's obvious from the code that pthread_mutex_unlock() was called right before pthread_mutex_destroy() and thus the mutex is not locked. So I believe the EBUSY value is being erroneously returned in this case. g++ -g -O2 -o test_ebusy_bug -lpthread test_ebusy_bug.cpp test_ebusy_bug.cpp: #include <vector> #include <thread> #include <pthread.h> #include <iostream> static const size_t tCnt = 10; struct test_struct { pthread_mutex_t mutex; pthread_cond_t cond1; pthread_cond_t cond2; bool run; std::vector<bool> runningList; test_struct() : run(false) , runningList(tCnt) { } void run_func(size_t index) { pthread_mutex_lock(&mutex); runningList[index] = true; pthread_cond_broadcast(&cond1); while (run) { pthread_cond_wait(&cond2, &mutex); } runningList[index] = false; pthread_mutex_unlock(&mutex); } bool spawn_join_threads() { std::vector<std::thread> tList; // Initialize the pthread variables pthread_mutex_init(&mutex, NULL); pthread_cond_init(&cond1, NULL); pthread_cond_init(&cond2, NULL); // Start all of the threads run = true; for (size_t i = 0; i < tCnt; i++) { runningList[i] = false; } for (size_t i = 0; i < tCnt; i++) { tList.push_back(std::thread(&test_struct::run_func, this, i)); } // Wait for all of the threads to start pthread_mutex_lock(&mutex); for (size_t i = 0; i < tCnt; i++) { while (!runningList[i]) { pthread_cond_wait(&cond1, &mutex); } } pthread_mutex_unlock(&mutex); // Stop all of the threads run = false; pthread_cond_broadcast(&cond2); for (int i = 0; i < tCnt; i++) { tList[i].join(); } tList.clear(); // Verify that all of the threads have stopped pthread_mutex_lock(&mutex); for (size_t i = 0; i < tCnt; i++) { if (runningList[i]) { std::cerr << "A thread hasn't stopped" << std::endl; pthread_mutex_unlock(&mutex); return false; } } pthread_mutex_unlock(&mutex); // Destroy the pthread variables int ret = pthread_cond_destroy(&cond2); if (ret) { std::cerr << "pthread_cond_destroy returned " << ret << std::endl; return false; } ret = pthread_cond_destroy(&cond1); if (ret) { std::cerr << "pthread_cond_destroy returned " << ret << std::endl; return false; } ret = pthread_mutex_destroy(&mutex); if (ret) { std::cerr << "pthread_mutex_destroy returned " << ret << std::endl; return false; } return true; } }; int main() { test_struct t; while (t.spawn_join_threads()); return 0; } Reproducible: Always Steps to Reproduce: Compile and run the above program. Actual Results: The program runs for awhile and then exits with the message: pthread_mutex_destroy returned 16 Expected Results: The program runs indefinitely without exiting. -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1131330 http://bugzilla.opensuse.org/show_bug.cgi?id=1131330#c2 Austin Beer <asbeer@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Flags|needinfo?(asbeer@gmail.com) | --- Comment #2 from Austin Beer <asbeer@gmail.com> --- I updated to the latest glibc version provided for OpenSUSE Leap 15.0, rebooted, re-ran the test, and unfortunately got the same error. The glibc I'm running is now glibc-2.26-lp150.11.14.2.x86_64. I see that SLES 15 has glibc-2.26-13.14.1.x86_64 available for it, but since I'm running OpenSUSE Leap 15.0 instead of SLES 15, I don't have access to that version of glibc. Is there a way for me to get access to that version of glibc so that I can install it on my system and test with it? -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1131330 http://bugzilla.opensuse.org/show_bug.cgi?id=1131330#c7 Austin Beer <asbeer@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Flags|needinfo?(asbeer@gmail.com) | --- Comment #7 from Austin Beer <asbeer@gmail.com> --- The system I performed my test on *does* have HLE. # lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 78 Model name: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz Stepping: 3 CPU MHz: 2500.000 CPU max MHz: 3000.0000 CPU min MHz: 400.0000 BogoMIPS: 4992.00 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 3072K NUMA node0 CPU(s): 0-3 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d -- You are receiving this mail because: You are on the CC list for the bug.
http://bugzilla.opensuse.org/show_bug.cgi?id=1131330 http://bugzilla.opensuse.org/show_bug.cgi?id=1131330#c8 --- Comment #8 from Austin Beer <asbeer@gmail.com> --- Both the POSIX specification and the Linux man pages indicate that pthread_mutex_destroy() should only return EBUSY when "The implementation has detected an attempt to destroy the object referenced by mutex while it is locked or referenced (for example, while being used in a pthread_cond_timedwait() or pthread_cond_wait()) by another thread." That is not the case in the test program that I provided, so I believe that the assumption that EBUSY should not occur is correct per the specification. https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_dest... https://linux.die.net/man/3/pthread_mutex_destroy -- You are receiving this mail because: You are on the CC list for the bug.
participants (1)
-
bugzilla_noreply@novell.com