CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Simple posix thread functions

    Gurus,

    I have to implement a very simple thread synchronization mechanism in Win32 as well as unix. I would like to use the Win32 API for Microsoft Windows platforms and standard Posix function calls for GCC unix platforms.

    For Win32, I used a semaphore (#include <Windows.h>) created with ::CreateSemaphore(...) with an initial count of one and a maximum count of one. In combination with the standard Win32 API function ::WaitForSingleObject(...), this works well and stisfies the development goals.

    Can anyone please tell me the similar, corresponding headers and functions calls for compilers such as GCC which are Posix comparible? Which headers are required? Does one have to link with libpthread or something GNU-ish which has to be installed previously?

    Just a few lines of code please. The mighty GNU package CommonC++ is too big for this particular application.

    Alternatively, does anyone know of a source for full Posix support for Microsoft compilers? Maybe it's there and I just don't know it.

    Thanks for any help.

    Chris.

    You're gonna go blind staring into that box all day.

  2. #2
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Simple solution found

    Found a simple solution.

    I used sem_init(...) with an initial count of one for initialization of a semaphore in combination with sem_wait(...) for locking and sem_post(...) for unlocking. For cleanup sem_destroy(...) was used.

    The necessary headers are <semaphore.h>, <sys/types.h>, <fcntl.h>.

    The simple thread synchronization was suitable for my design needs.

    Chris.

    You're gonna go blind staring into that box all day.

  3. #3
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Cool, thanks for posting the answer
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured