How do you thread?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

View Poll Results: What threading library do you use?

Voters
13. You may not vote on this poll
  • POSIX

    3 23.08%
  • Boost

    4 30.77%
  • C++1x

    1 7.69%
  • Other (Win API, wxWidgets...)

    5 38.46%
Results 1 to 13 of 13

Thread: How do you thread?

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

    How do you thread?

    I'm just curious. When you write multithreaded applications, how do you do the threading?

    I almost invariably use POSIX. As a C programmer, I'm very familiar with it and it's available on all the platforms that my company and my personal projects care about.

  2. #2
    Join Date
    Aug 2008
    Posts
    902

    Re: How do you thread?

    I use a pthread wrapper atm, but once Mingw gets C++1x threads working, I'll switch to that.

  3. #3
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,110

    Re: How do you thread?

    I am using boost::thread

  4. #4
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,725

    Re: How do you thread?

    We're exclusively Windows here, so we use the Afx functions.
    We make a lot of use of the WaitForMultipleObjects call, which I don't think has an exact equivalent in the other APIs.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  5. #5
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,014

    Re: How do you thread?

    We program for Windows too, but I prefer Boost.Thread over the Win API (or MFC wrappers). I find that the Windows stuff makes it too easy to develop a bad design. When you restrict yourself to the boost stuff, a good design seems to come more natural.
    Quote Originally Posted by JohnW@Wessex View Post
    We make a lot of use of the WaitForMultipleObjects call, which I don't think has an exact equivalent in the other APIs.
    Boost has the wait_for_all function.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,470

    Re: How do you thread?

    Quote Originally Posted by JohnW@Wessex View Post
    We're exclusively Windows here, so we use the Afx functions.
    We make a lot of use of the WaitForMultipleObjects call, which I don't think has an exact equivalent in the other APIs.
    Totally agree!
    I use MFC and therefore its CWinThread class and AfxBeginThread to start secondary threads.

    Unfortunately I cannot vote because there is no such a choice like "MFC".
    Victor Nijegorodov

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: How do you thread?

    I have a custom thread-pool class which is built on top of Boost Threads. However, it also has a pthread-like API for use in C.

  8. #8
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Lightbulb Re: How do you thread?

    Quote Originally Posted by VictorN View Post
    Totally agree!
    I use MFC and therefore its CWinThread class and AfxBeginThread to start secondary threads.

    Unfortunately I cannot vote because there is no such a choice like "MFC".
    Sure you can! That's what the "other" option is for.

  9. #9
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,470

    Re: How do you thread?

    Quote Originally Posted by kempofighter View Post
    Sure you can! That's what the "other" option is for.
    No, MFC is absent in the list of what "other" contains...
    Victor Nijegorodov

  10. #10
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Re: How do you thread?

    Quote Originally Posted by VictorN View Post
    No, MFC is absent in the list of what "other" contains...
    Seriously? What do you think the "...." means?

  11. #11
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,470

    Re: How do you thread?

    Something from
    • Win API
    • wxWidgets
    • < ellipsis >
    Victor Nijegorodov

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

    Re: How do you thread?

    I'm using Intel TBB (the open source version)

    http://threadingbuildingblocks.org/

    The emphasis is on lightweight multicore multitasking but it supports traditional heavyweight threading too.

    It also features an efficient concurrent object allocator you can use to replace the standard allocator that comes with the compiler.

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,358

    Re: How do you thread?

    I code only on Windows and exclusively use _beginthreadex for thread creation.

    If I code in MFC, I still use _beginthreadex instead of AfxBeginThread because I never create secondary UI threads.

    I also wrap the thread sync primitives (cs, mutex, etc.) and use an auto locker class to help with thread synchronization.

    Something like:

    Code:
    {
      // Acquire the lock
      AutoLock< CriticalSectionLock> lock( &m_lock );
    
      //
      // Access data
      //
    } // lock auto released here

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center