First, start the thread
void do_something (); Std::thread t (do_something);
Note that T is the thread that is created, do_something is a function object, and do not pass in the function. The provided function objects are copied into the storage space of the new thread, and the execution and invocation of the function objects are performed in the memory space of the threads.
Join (), detach ()
Two, line path ginseng
Thread invocation pass-through parameter
void f (int i,std::string const& s); Std::thread t (f,3, "Hello");
Note that thread initialization does not implicitly convert misinform parameters, and requires an explicit conversion.
Iii. Transfer of thread ownership
Std::move () to transfer thread ownership, the source thread is not associated with the execution thread after the transfer.
void some_function (); void // 1// 2// 3// 4// 5 // 6 The assignment will crash the program, and T1 already has a thread.
Four, the runtime determines the number of threads
Std::thread::hardware_concurrency () This function returns the number of threads that can concurrently concurrent in a program. For example, in multicore systems, the return value can be the number of CPU cores. Because a context-sensitive switchover can degrade the performance of a thread, there are certainly fewer threads to start than the number of threads supported by the hardware.
Concurrent Programming (2) thread management