multithreading - Why c++ threads are movable but not copiable? -


as title of question says, why c++ threads (std::thread , pthread) movable not copiable? consequences there, if make copiable?

regarding copying, consider following snippet:

void foo();  std::thread first (foo);      std::thread second = first; // (*) 

when line marked (*) takes place, presumably of foo executed. expected behavior be, then? execute foo start? halt thread, copy registers , state, , rerun there?

in particular, given function objects part of standard, it's easy launch thread performs same operation earlier thread, reusing function object.

there's not motivation begin this, therefore.


regarding moves, though, consider following:

std::vector<std::thread> threads; 

without move semantics, problematic: when vector needs internally resize, how move elements buffer? see more on here.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -