0

I have a C++ application which needs to be multi-threaded in windows platform. After browsing some forums, I gave CreateThread API a try. Here is the link giving details regarding its signature.

But, it always throws Access violation error and after going through some more forums, I got a bit confused when they said that this API has always had some problems. Some have recommended to use BeginThreadEx.

What is your recommendation for threading model implementation? Also, give reasons for your recommendation.

Sankalp
  • 2,709
  • 2
  • 26
  • 40
  • 3
    "...they said that this API has always had some problems..." I think there were definitely problems involved, but I have doubts their origins were with the Windows API. There are *runtime* library issues that historically needed accounting for proper setup of MS CRT (thats likely the `_beginthreadex` you're referring to). You may find [this question and answers](http://stackoverflow.com/questions/331536/windows-threading-beginthread-vs-beginthreadex-vs-createthread-c) an interesting read. – WhozCraig Feb 28 '14 at 06:45
  • 4
    The [`CreateThread`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx) function is the native way of creating threads on Windows. No matter which other API you use, in the end there's going to be a call to `CreateThread` if you're on Windows. – Some programmer dude Feb 28 '14 at 06:47
  • @WhozCraig Thanks for the link to the question! – Sankalp Feb 28 '14 at 06:53
  • If your compiler supports C++11, why not use `std::thread`, it's much cleaner and is cross-platform. –  Feb 28 '14 at 06:54
  • @DavidOtano Yeah..but sadly, C++11 is still not supported here – Sankalp Feb 28 '14 at 06:58
  • @Joachim well I could theoretically use the actual nt calls amd and it ;) but really I can't think of a single reason to use CreateThread. – Voo Feb 28 '14 at 10:55

0 Answers0