A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/thread/thread/ below:

class

<thread>

std::thread

Thread

Class to represent individual threads of execution.

A thread of execution is a sequence of instructions that can be executed concurrently with other such sequences in multithreading environments, while sharing a same address space.

An initialized thread object represents an active thread of execution; Such a thread object is joinable, and has a unique thread id.

A default-constructed (non-initialized) thread object is not joinable, and its thread id is common for all non-joinable threads.

A joinable thread becomes not joinable if moved from, or if either join or detach are called on them.



Member types
id
Thread id (public member type)
native_handle_type
Native handle type (public member type)

Member functions
(constructor)
Construct thread (public member function)
(destructor)
Thread destructor (public member function)
operator=
Move-assign thread (public member function)
get_id
Get thread id (public member function)
joinable
Check if joinable (public member function)
join
Join thread (public member function)
detach
Detach thread (public member function)
swap
Swap threads (public member function)
native_handle
Get native handle (public member function)
hardware_concurrency [static]
Detect hardware concurrency (public static member function)

Non-member overloads
swap (thread)
Swap threads (function)

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// thread example
#include <iostream>       // std::cout
#include <thread>         // std::thread
 
void foo() 
{
  // do stuff...
}

void bar(int x)
{
  // do stuff...
}

int main() 
{
  std::thread first (foo);     // spawn new thread that calls foo()
  std::thread second (bar,0);  // spawn new thread that calls bar(0)

  std::cout << "main, foo and bar now execute concurrently...\n";

  // synchronize threads:
  first.join();                // pauses until first finishes
  second.join();               // pauses until second finishes

  std::cout << "foo and bar completed.\n";

  return 0;
}

Output:
main, foo and bar now execute concurrently...
foo and bar completed.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4