Search code examples
cygwinsemaphoremingw-w64msys2

What tool with gcc under Windows can make a console program with working named semaphores (sem_open)?


Try to do a gcc compiled portable (Linux and Windows) console program. For Windows 7 I use gcc version 8.1.0, i686-posix-dwarf-rev0, Built by MinGW-W64 project.

Have no compile errors. But have got "sem_open: Function not implemented" on execution under Windows.

Does some another tool with gcc (like Cygwin or MSYS2) support named semaphores with sem_open()?

Thanks.


Solution

  • I would not describe either Cygwin or MSYS2 as mere "tools", as they are entire software distributions each of which rely on a special runtime library. However, MSYS2 would not be a solution to your problem. Unlike Cygwin, the purpose of MSYS2 is not to provide a full POSIX emulation layer. See How does MSYS2 differ from Cygwin.

    If you build your problem using the Cygwin toolchain you will have support for most common POSIX APIs, including sem_open. However, your program will be dependent on the entire Cygwin runtime, so you must include with it cygwin1.dll, at the very least.

    Alternatively, although you weren't exactly clear on what you're trying to do, you can implement named semaphores in your Windows port using the native Windows API for semaphore objects. Here's a nice little library that supplies (approximate; possibly good enough for your needs) POSIX semaphores implemented on top of Windows's native API, though I haven't used it so I make no guarantees as to its robustness, more just that it provides a good example.