Go Back   ZeroC Forums > Bug Reports

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 05-24-2004
stefan stefan is offline
Registered User
 
 
Join Date: May 2004
Posts: 3
return value of pthread_mutex_trylock() not check properly

I'm trying to get Ice working under FreeBSD.

It builds fine but make test fails:

Code:
running mutex test... ../../../include/IceUtil/Mutex.h:323: IceUtil::ThreadSyscallException:
thread syscall exception: Resource deadlock avoided failed
test mutex failed
After some investigation it turned out that in Mutex.h the return value of pthread_mutex_trylock() is tested against EBUSY. But the new threading library in FreeBSD returns EDEADLK (which seems to be okay according to the standard).

This simple patch solves the problem:

Code:
--- include/IceUtil/Mutex.h.orig        Sun May 23 23:52:37 2004
+++ include/IceUtil/Mutex.h     Sun May 23 23:54:30 2004
@@ -318,7 +318,7 @@
 Mutex::tryLock() const
 {
     int rc = pthread_mutex_trylock(&_mutex);
-    if(rc != 0 && rc != EBUSY)
+    if(rc != 0 && rc != EBUSY && rc != EDEADLK)
     {
        throw ThreadSyscallException(__FILE__, __LINE__, rc);
     }
Exactly the same problem occurs in StaticMutex.h.

After patching both header files make test just works fine.
Reply With Quote
  #2 (permalink)  
Old 05-24-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 962
Welcome to the forum!

If Mutex::tryLock receives EDEADLK, it indicates an application error because it means an application thread is attempting to recursively lock a non-recursive mutex. It is appropriate for an exception to be raised in this case.

So, either there is a bug in the test suite, or the FreeBSD threading library is misbehaving. Can you build Ice in debug mode and provide a stack trace of the test failure? Note that you can run the test directly by executing test/IceUtil/thread/client.

Thanks,
- Mark
Reply With Quote
  #3 (permalink)  
Old 05-25-2004
stefan stefan is offline
Registered User
 
 
Join Date: May 2004
Posts: 3
Unfortunately gdb has troubles with the threading library and I'm unable to get a backtrace.

I put in some debug information to track the failing test down:

This is around line 126 in MutexTest.cpp:
Code:
Mutex::TryLock lock2(mutex); std::cerr << "this get's printed\n";
test(lock.tryAcquire() == false); std::cerr << "we never reach this\n";
The return value of pthread_mutex_trylock() in Mutex.h is EDEADLK with the new threading library (it was EBUSY with the old one) which causes the ThreadSyscallException to be thrown.

Sorry again that I can't provide a backtrace but I hope this is information somewhat useful to you.
Reply With Quote
  #4 (permalink)  
Old 05-25-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 962
Ok, now I strongly suspect a bug in the FreeBSD threading library you are using.

The C equivalent of the test to this point is pretty simple:
Code:
pthread_mutex_init(...);
pthread_mutex_lock(...);
pthread_mutex_unlock(...);
pthread_mutex_trylock(...);
The call to trylock should not be returning EDEADLK in this case, since the mutex has clearly been unlocked.

Perhaps you should submit this test to the FreeBSD folks as a bug report.

Take care,
- Mark
Reply With Quote
  #5 (permalink)  
Old 05-25-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 962
Please ignore my previous reply. A colleague graciously pointed out that I was quite wrong. Thanks Benoit.

It appears from this link that pthread_mutex_trylock on FreeBSD raises EDEADLK in some circumstances and EBUSY in others.

At this point we would prefer not to mask the EDEADLK result by modifying Mutex::tryLock as you suggested, so we will modify the tests to trap IceUtil::ThreadSyscallException and check the result code.

Thanks,
- Mark
Reply With Quote
  #6 (permalink)  
Old 05-29-2004
stefan stefan is offline
Registered User
 
 
Join Date: May 2004
Posts: 3
Thanks for your quick replies and the inclusion of the fixes in Ice 1.4.

Unfortunately I missed that the monitor<mutex> test fails just for the same reason (because it was obscured by my Mutex.h patch).

The failing code is test/IceUtil/thread/MonitorMutexTest.cpp, line 111:
Code:
Monitor<Mutex>::TryLock tlock(monitor);
Would be great if this could be integrated too for later releases.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ice with C# not multi-threading properly amrufon Help Center 12 09-15-2006 03:09 AM
Suggestion to add daemon check to Ice::Service ctennis Comments 2 03-29-2006 03:27 PM
why return false ? OrNot Help Center 2 01-04-2006 01:50 AM
Properly shutting ICE down. litghost Help Center 8 11-25-2005 07:01 PM
Can Ice dynamically check and update its registry infomation when a Ice server dies? rc_hz Help Center 3 11-15-2004 09:04 AM


All times are GMT -4. The time now is 03:11 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.