Hi Andy,

OpenThreads doesn't at present have support to reentrant/recusive
mutexs so the behavior you've come across is expected, I need it in
the OSG a while back so implementated the osgDB::ReentrantMutex.

In general you shouldn't need ReenetrantMutex's, but in some cases
they are the only way to code something.  I'm certainly open to moving
ReentantMutex into OpenThreads, or changing OpenThreads::Mutex to
include support for it.  PTHREAD_MUTEX_RECURSIVE isn't available on
all versions of pthreads though, so we'd need a fallback if we were to
use it.

Robert.

On 2/8/07, Andrew Somerville <[EMAIL PROTECTED]> wrote:
Hey,

I noticed while debugging a deadlock in ossimPlanet that OpenThreads
uses PTHREAD_MUTEX_NORMAL (rather than PTHREAD_MUTEX_RECURSIVE) mutexes.
As a result, a mutex locked more than once from the same thread thread
will block, which is often not the behavior desired. Is this intentional?

There doesnt seem to be another OpenThreads mutex type which uses
PTHREAD_MUTEX_RECURSIVE nor does it seem that the standard mutex can be
changed to this type.

So the question is, is this intentional or a mistake? Is there a way to
invoke the PTHREAD_MUTEX_RECURSIVE behavior?

The following is an example program which illustrates the issue:

/////////////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <list>
#include <string>
#include <OpenThreads/Mutex>
#include <OpenThreads/ScopedLock>
using namespace std;
using namespace OpenThreads;

class Base
{
        public:
                Base() { }
                void foo()
                {
                        printf("inside foo\n");
                        ScopedLock<Mutex> lock( theMutex );
                        // lots of code
                        bar();
                        // lots more code
                }

                void bar()
                {
                        printf( "inside bar\n");
                        ScopedLock<Mutex> lock( theMutex ); //Oops
...deadlock if called from foo
                }

        protected:

                Mutex theMutex;
};

int main()
{
        printf("OpenThreads mutex text\n");
        Base myBase;

        myBase.bar(); // fine
        myBase.foo(); // deadlock

        printf("Done\n");
        return 0;
}
/////////////////////////////////////////////////////////////////////////



      Andy

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to