Thread: Porting Unix to windows: semaphores/sem_open

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    41

    Porting Unix to windows: semaphores/sem_open

    So, I am porting a large C program into windows... and we are so very close to completion. Unfortunately this has to be done natively so things like SUA and Cygwin aren't an option.

    we are using win32pthreads and Mingw to get this done

    So one of the functions uses the sem_open cal which normally lives in semaphore.h and does so in win32pthreads, unfortunately after spending some time figuring out why it dies there I noticed that the implementation pretty much just returns an error... wonderful.

    in either case; is there any direct alternative I can use in windows? or has anyone else ran into this issue before in windows. I am eyeballing sem_init and a little code finagling might be able to work.

    We are using server 2008 to build.

    any input is greatly appreciated.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You could do a fairly straight forward port using Win32 semaphore objects: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    sem_init, sem_open = CreateSemaphore()/OpenSemaphore()
    sem_close, sem_destroy, sem_unlink = CloseHandle()
    sem_wait, sem_trywait, sem_timedwait = one of wait functions: WaitFor[Single|Multiple]Object[s]()
    sem_post = ReleaseSemaphore()
    sem_getvalue = available via ReleaseSemaphore()

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread and socket porting from Linux to Windows
    By mynickmynick in forum C Programming
    Replies: 2
    Last Post: 07-18-2008, 06:57 AM
  2. Connecting windows through Unix
    By vin_pll in forum Tech Board
    Replies: 10
    Last Post: 06-23-2008, 10:32 PM
  3. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM
  4. How May I connect from Windows NT to Unix
    By jose luis in forum C Programming
    Replies: 3
    Last Post: 08-22-2002, 03:12 PM
  5. Windows or Unix environment
    By ghe1 in forum Windows Programming
    Replies: 5
    Last Post: 02-19-2002, 11:37 AM