C ++ multi-threaded base study notes (IX)

A, std :: atomic continued to talk

Speaking of std :: atomic previous chapter is for a variable, add the variable here is generally for the operation ++, + =, -, & =, and so on operations. The following Such undesirable: a = a + 1;

Two, std :: async and std :: std :: thread difference

When 1.std :: async first argument is std :: lauch :: async, will be forced to create a thread, more precisely, it is to create an asynchronous task, and std :: thread sometimes due to resource constraints, creating a thread fail, causing program crashes reported abnormal.

When 2.std :: saync second parameter is the std :: lauch :: deferred, and will not create a new thread, but to create a synchronization task, when you call the member function get (), it will call the entry functions.

 

Guess you like

Origin www.cnblogs.com/main404/p/11279441.html