Hi,

It seems that there is a difference in behavior when using the OpenThreads::Mutex class in Linux and Windows.

For our (crossplatform) application it is required to synchronize data between two different threads. In order to prevent a race condition, we used the OpenThreads mutex lock (OpenSceneGraph 2.6.1). To test the behavior of the mutex lock, I created a small application (attached below).

Our Linux machine produces the following output:
[laure...@fedora mutex_test]$ ./main
test 1 (trylock): ok
-- application blocked --

Using the same application under windows (compiled with mingw):
main.exe
test 1 (trylock): ok
test 2 (lock): ok
test 3 (lock again): ok
test 4 (unlock): ok
-- application finished --

The Linux version shows the correct behavior, the Windows version seems to ignore the lock calls and does not block at all.

Questions:
1. Are additional settings required to use the OpenThreads mutex lock under windows? 2. What alternatives are available for the OpenThreads mutex lock? (Manually implement calls using pthread?)

Kind Regards,
- Laurence

---------
// main.cpp
// g++ main.cpp -o main -I /home/userx/osg/include -L /home/userx/osg/lib -lOpenThreads

#include <stdlib.h>
#include <iostream>
#include <OpenThreads/Mutex>
using namespace std;

OpenThreads::Mutex *mt_sync;

int main(int argc, char **argv)
{
   mt_sync = new OpenThreads::Mutex();

   printf("test 1 (trylock): ");
   if(mt_sync->trylock() == 0)
       printf("ok\n");
   else
       printf("fail\n");

   printf("test 2 (lock): ");
   if(mt_sync->lock() == 0)
       printf("ok\n");
   else
       printf("fail\n");

   printf("test 3 (lock again): ");
   if(mt_sync->lock() == 0)
       printf("ok\n");
   else
       printf("fail\n");

   printf("test 4 (unlock): ");
   if(mt_sync->unlock() == 0)
       printf("ok\n");
   else
       printf("fail\n");

   delete mt_sync;

   return 0;
}


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to