GNOME Bugzilla – Bug 660096
glib/rwlock tests failure (tests asserted)
Last modified: 2011-09-26 12:56:07 UTC
Hi, When running the rwlock tests on Windows XP, tests #3 and #6 failed as they asserted, with the following output: (debug) GThread using Windows XP mode <snip> /thread/rwlock3: ** ERROR:..\..\..\glib\tests\rwlock.c:59:???: assertion failed: (!ret) <snip, taken from another run with test #3 commented out> /thread/rwlock6: ** ERROR:..\..\..\glib\tests\rwlock.c:103:???: assertion failed: (!ret) By the way, theses tests ran fine on Windows 7, where the workaround code for RWLock etc is not required. Thank you, and God bless!
Tricky. This is caused by the fact that CRITICAL_SECTION (on which the Windows XP reader-writer lock emulation is based) is recursive, and the testcase works by acquiring the lock, then testing that it is unable to acquire it again: ret = g_rw_lock_writer_trylock (&lock); g_assert (ret); ret = g_rw_lock_writer_trylock (&lock); g_assert (!ret); I may have to add a double-check to circumvent the recursive nature of CRITICAL_SECTION.
Created attachment 197451 [details] [review] winxp threads: detect SRWLock emulation reentrancy We lack SRWLock on Windows XP, so we use CRITICAL_SECTION to emulate it there. SRWLock is non-recursive, but CRITICAL_SECTION will happily allow itself to be acquired multiple times by the same thread. We need to detect if our second acquire succeeded because of the recursive nature of CRITICAL_SECTION. In the case of a _lock() operation, we would normally have deadlocked, so abort. In the case of a _trylock() operation, we need to ensure that FALSE is properly returned. Problem caught by Matthias Clasen and Chun-wei Fan.
Hi Ryan, Your patch worked fine on XP-I will test again on Win7/x64 a bit later. However, another issue that popped up on XP is that the gwakeup.c test under gthread would -sometimes- get caught in an infinite loop when it does the /gwakeup/threaded test. Please let me know if more info is needed here-sorry, couldn't collect that now because I need to head out soon. Again, this did not occur on Windows7. Thank you, and God bless!
Hi Ryan, It seems that problem in comment #3 existed before your patch, so it shouldn't have been introduced by your patch. Thank you, and God bless!
Thanks for the review. Attachment 197451 [details] pushed as fdc594e - winxp threads: detect SRWLock emulation reentrancy