Date: Tue, 03 Mar 2015 10:40:14 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-doc@FreeBSD.org Subject: [Bug 198216] According to man page for pthread_cond_destroy it returns EBUSY error code, but it never does Message-ID: <bug-198216-9@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=198216 Bug ID: 198216 Summary: According to man page for pthread_cond_destroy it returns EBUSY error code, but it never does Product: Documentation Version: Latest Hardware: Any URL: https://www.freebsd.org/cgi/man.cgi?query=pthread_cond _destroy&apropos=0&sektion=3&manpath=FreeBSD+11-curren t&arch=default&format=html OS: Any Status: New Severity: Affects Many People Priority: --- Component: Documentation Assignee: freebsd-doc@FreeBSD.org Reporter: msiodelski@gmail.com I am using the following FreeBSD version: 10.1-RELEASE-p6 FreeBSD 10.1-RELEASE-p6 #0 r279272: Wed Feb 25 12:27:40 CET 2015 built from the following svn branch: ^/releng/10.1 According to the man pages for the pthread_cond_destroy, it returns the following error codes: ERRORS The pthread_cond_destroy() function will fail if: [EINVAL] The value specified by cond is invalid. [EBUSY] The variable cond is locked by another thread. In the course of my testing I found that this function actually never returns EBUSY error code if the conditional variable is locked by another thread. Briefly looking at the pthread_cond_destroy implementation in /usr/src/lib/libthr/thread/thr_cond.c I don't see any checks for variable being locked by another thread: int _pthread_cond_destroy(pthread_cond_t *cond) { struct pthread_cond *cvp; int error = 0; if ((cvp = *cond) == THR_COND_INITIALIZER) error = 0; else if (cvp == THR_COND_DESTROYED) error = EINVAL; else { cvp = *cond; *cond = THR_COND_DESTROYED; /* * Free the memory allocated for the condition * variable structure: */ free(cvp); } return (error); } So it seems that one of the: documentation or the code is wrong. Some background about how it was tested. I am working on the Kea DHCP server implementation (kea.isc.org). One of our unit tests is exercising the scenario of trying to destroy the cond variable while it is locked by another thread. The expected behavior is that the pthread_cond_destroy fails with non-success status code, but it returns 0. However, this test uses C++ objects and infrastructure of our implementation and it hasn't been isolated as standalone test. If you find it useful to have such a standalone test which demonstrates the behavior, I can write one. For your convenience I am sending the locations of our source code where we run the test nested in our implementation: https://github.com/isc-projects/kea/blob/master/src/lib/util/threads/tests/condvar_unittest.cc (see the destroyWhileWait test). and the source code of the CondVar class under test: https://github.com/isc-projects/kea/blob/master/src/lib/util/threads/sync.cc Note that the destructor of the CondVar class calls the pthread_cond_destroy and then performs an assert that the status code is 0. For this test it should be non-zero and the process should die as expected by the test. But, it doesn't. Hope that helps. -- You are receiving this mail because: You are the assignee for the bug.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-198216-9>