CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2002
    Posts
    2,543

    Cross-platform development

    I need to write program package for using in different OS. For Windows only, I could use the following API:
    1) CreateThread or _beginthreadex for multithreading
    2) CreateEvelt, WaitForSingleObject, WaitForMultipleObjects, InitilazeCriticalSection etc. - for thread synchronization
    3) CreateFile, ReadFile etc. - for file handling
    4) CreateFile, ReadFile etc. - for serial communications.

    Now, I need to implement all this stuff for using in different OS. What are my options?

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Cross-platform development

    For (1) and (2), the most common options are pthreads (C-based) and Boost Threads (C++-based).

    For (3), the C standard of course provides FILE*s, fprintf/fscanf/etc, and the C++ standards provides ifstreams and ofstreams. Which of those you choose to use is largely based on personal preference. The C functions are a bit faster, but the C++ functions are type-safe.

    For (4), you can of course use the Berkley Sockets interface; I believe most of the WinSock functions are aliased to this anyway. However, this is a very low-level approach. One alternative is the Boost ASIO library, which I believe includes socket IO classes which fit into the C++ iostreams framework.

  3. #3
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Cross-platform development

    Thank you,
    p. 4 is about serial communications (COM port), and not sockets. What about this?

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Cross-platform development

    No direct experience with that, sorry. I guess I assumed you meant "serialized", eg network, communications.

  5. #5
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Cross-platform development

    I found serial_port class in the Boost library. It looks like Boost has everything I need. Thank you.

  6. #6
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Cross-platform development

    1) 2) pthreads is very nice, I use them in cross platform development, there is a hitch though. There is no Windows x64 version of pthreads, nor are there any plans for it.

    3) fopen, fclose, fgets...

    4) This one, I don't know about. I use serial communication myself, but I turn the feature off when compiling the software for *nix. If you come up with a good solution, let me know

  7. #7
    Join Date
    May 2009
    Posts
    2,413

    Re: Cross-platform development

    Quote Originally Posted by Alex F View Post
    1) CreateThread or _beginthreadex for multithreading
    2) CreateEvelt, WaitForSingleObject, WaitForMultipleObjects, InitilazeCriticalSection etc. - for thread synchronization
    Note that mutithreading will be in the next C++ standard,

    http://www.devx.com/SpecialReports/Article/38883

  8. #8
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Cross-platform development

    That's true, and C++ 0x (... is it 1x now?) uses regular types for arguments, whereas currently, you're stuck using a single opaque pointer (using POSIX)

  9. #9
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Cross-platform development

    The C++0x threading mechanism is supposed to be heavily based on Boost Threads, wherein you write a functor to start the thread if you need to pass in data, rather than relying on a void* like pthreads.

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