Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many threads can a C++ application create

Tags:

I'd like to know, how many threads can a C++ application create at most. Does OS, hardware caps and other factors influence on these bounds?

like image 998
Felype Avatar asked Jun 27 '13 14:06

Felype


People also ask

How many threads can I make in C?

The pthread_create() function can only create one thread.

How many threads we can create?

On Windows machines, there's no limit specified for threads. Thus, we can create as many threads as we want, until our system runs out of available system memory.

How many threads should an application use?

General rule of thumb for threading an application: 1 thread per CPU Core. On a quad core PC that means 4. As was noted, the XBox 360 however has 3 cores but 2 hardware threads each, so 6 threads in this case.

How many threads can a computer run at once?

A single CPU core can have up-to 2 threads per core. For example, if a CPU is dual core (i.e., 2 cores) it will have 4 threads.


1 Answers

[C++11: 1.10/1]: [..] Under a hosted implementation, a C++ program can have more than one thread running concurrently. [..] Under a freestanding implementation, it is implementation-defined whether a program can have more than one thread of execution.

[C++11: 30.3/1]: 30.3 describes components that can be used to create and manage threads. [ Note: These threads are intended to map one-to-one with operating system threads. —end note ]

So, basically, it's totally up to the implementation & OS; C++ doesn't care!

It doesn't even list a recommendation in Annex B "Implementation quantities"! (which seems like an omission, actually).

like image 164
Lightness Races in Orbit Avatar answered Oct 23 '22 06:10

Lightness Races in Orbit