This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

semaphores


I'm new to using pthreads-win32 (SNAPSHOT 2002-03-02), and I have to port 
a program from Linux to Windows 2000. A bug has somehow crept into my
code, and I've narrowed the problem area down to a code fragment similar
to the following:
 
#include <semaphore.h>
#include <cassert>
#include <iostream>
 
using namespace std;
 
int main()
{
   /**
    * We want to check wether a semaphore can be initialised
    * with a value.
    */
  
   // a semaphore
   sem_t psem;
 
   // initialise it with value 10
   assert(sem_init(&psem,0,10) == 0);                       // ASSERT NO 1
   // if the semaphore initialisation was ok, the sem
   // should now have the value 10
   int ret = 0;
   assert(sem_getvalue(&psem,&ret) == 0);               // ASSERT NO 2
   // if no errors occured then value is now in the
   // integer ret
   cout << endl << "sem_getvalue() returns value " << ret << endl << flush;
 
   return 0;
}
 
I'm using MS VC++ 6.0, and I'm linking with the precompiled pthreadVCE.lib library.
At runtime, the first assert() passes OK, but second fails.
I have no idea why this fails (hopefully it's simply a newby error, and not a bug in
the pthreads-win32 lib), but it does.
 
Thanks
Rob

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]