locked
Is it ok to use _beginThread in metro?

    Question

  • Hi,

    I am trying to migrate the existed win32 multi-thread code of a COM component to metro and I found there seems to be some missing pieces about how to do proper thread creation. The CreateThread function is gone for sure. But how about _beginThread in CRT? The _beginThread seems ok to be use for it is not in the Desktop family,.  However, from my understanding, the _beginThread utilize the CreateThread in its implementation, it would be odd to be able to use _beginThread. So I do need some confirmation on: Is it ok to use _beginThread for thread creation in metro? If it is not ok,  what should I do to get the old win32 threading back to life?

    Thanks

    Tuesday, November 8, 2011 6:54 AM

Answers

  • If you want an experience of multi-threaded programming which is consistent across languages, then you should use the Windows Runtime ThreadPool API (Windows::System::Threading::ThreadPool).

    However, if you want to do fine-grained programming in C++, then you should use standard constructs such as std::thread and std::future.  The Parallel Patterns Library (found in ppl.h) also provides some intuitive patterns for parallel programming.

    If you use the above set of APIs, you will not have to worry about the underlying implementation details like whether CreateThread is called or not.

    Thanks


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Proposed as answer by Tom Taylor [MSFT]1 Thursday, November 17, 2011 11:53 PM
    • Marked as answer by Bob_Bao Wednesday, December 7, 2011 9:41 AM
    Thursday, November 10, 2011 12:57 AM

All replies

  • DIY answer: I switch thread creation from CreateThread to _beginthread, and the app passed the verification. 
    Wednesday, November 9, 2011 2:48 AM
  • If you want an experience of multi-threaded programming which is consistent across languages, then you should use the Windows Runtime ThreadPool API (Windows::System::Threading::ThreadPool).

    However, if you want to do fine-grained programming in C++, then you should use standard constructs such as std::thread and std::future.  The Parallel Patterns Library (found in ppl.h) also provides some intuitive patterns for parallel programming.

    If you use the above set of APIs, you will not have to worry about the underlying implementation details like whether CreateThread is called or not.

    Thanks


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Proposed as answer by Tom Taylor [MSFT]1 Thursday, November 17, 2011 11:53 PM
    • Marked as answer by Bob_Bao Wednesday, December 7, 2011 9:41 AM
    Thursday, November 10, 2011 12:57 AM