Reputation: 11439
Coming from C# / Java programming, creating new threads in programs tends to add a significant amount of overhead (for example 1MB per thread in C#). I was curious what kind of overhead do C++11 threads introduce.
Upvotes: 2
Views: 312
Reputation: 11126
C++ offers a fairly thin wrapper on top of the underlying implementation, leading to no significant additional overhead. In fact, you can even get a handle to the underlying OS thread, which will be a __gthread_t
, which is a pthread handle for g++ and a WINAPI thread handle for Visual C++.
However, threads do have intrinsic overhead, because they need to be scheduled by the OS, contain a stack and so forth.
An analysis by Mark Russinovich goes through the limits of thread creation under Windows. These limits are of course caused by the thread overhead and give:
Upvotes: 8
Reputation: 5221
Already solved here:
How much overhead is there when creating a thread?
Cliff Notes: this will be system dependent and the best way to know is to benchmark on your target system.
Upvotes: 3