Thread: Cross platform multithreading

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    113

    Cross platform multithreading

    Hi all,

    I am working in an application in which I have to create multithreaded application.
    I want to know that ,is it possible to make multithreaded application cross platform ?
    Since I have saw that mainly OS API's are used for this.....
    Is there any way for creating it ???

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Make your own.

    Look at the available thread APIs across the platforms you need to support, and decide what's important to you.

    Then your code has say
    myThreadHandle myThreadCreate ( void (*entryPt)(void*), void *param );


    You then have two implementation files, say
    mythread_linux.c
    mythread_win32.c
    BOTH of which implement
    Code:
    myThreadHandle myThreadCreate ( void (*entryPt)(void*), void *param ) {
      // do stuff to create a thread
    }
    You then link with the implementation file of your chosen platform.

    Then say, if you later on want to port to BSD as well, it's a simple matter of writing a single (and hopefully pretty trivial)
    mythread_bsd.c
    which re-implements your thread API on the new platform.

    The other 99% of your code is blissfully unaware that anything has happened.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    113
    Thanks for reply.....
    Is there any available library for this like third party library etc...

    Thanks

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Is _beginthread and the others not standard C, or is that for windows only?
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Some, but they come with baggage
    http://en.wikipedia.org/wiki/Netscape_Portable_Runtime

    Maybe it's reasonably partitioned to only link the bits you need.

    Try sourceforge as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The boost library reportedly has threading support. I've never used it though, so I'm not sure how comprehensive it is.

    _beginthread() is windows specific (IIRC, it is actually Microsoft compiler/library specific, although a couple of other vendors support it grudgingly).

    On the topic of frameworks with baggage, there is also The ACE framework. When I say baggage, I'm not exagerating: ACE is a framework for communication between processes/threads/systems and multithreading support is a small part of that.

  7. #7
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    You could also take a look at OpenMP. It has supports from different compilers (including Visual Studio since 2005 (but I don't know if the Express edition supports it) and GCC since version 4.2). It's totally platform independant and it's quite easy to use. I already used it a few times in some small projects and indeed, it works.
    I hate real numbers.

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    boost::thread is fairly comprehensive with little to no baggage.
    boost has other libraries that can help in a cross-platform project.
    http://www.boost.org/

    [edit]Although it's C++, not C[/edit]

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. List All files recursively cross platform
    By umen242 in forum C++ Programming
    Replies: 15
    Last Post: 05-07-2008, 01:20 PM
  2. Cross platform XML library
    By Josh Kasten in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2007, 04:04 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. cross platform game programming
    By xddxogm3 in forum Game Programming
    Replies: 13
    Last Post: 08-22-2004, 09:40 AM