sircodesalot
sircodesalot

Reputation: 11439

What kind of overhead to c++11 threads introduce?

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

Answers (2)

danielschemmel
danielschemmel

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:

  • A thread requires about 1 MB of virtual address space (default linker setting)
  • 4-16 KB of initial commit size
  • 12-48 KB of nonpageable memory

Upvotes: 8

It'sPete
It'sPete

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

Related Questions