mercredi 27 janvier 2016

std::thread constructor with no parameter

According to cppreference.com, std::thread constructor with no parameter means:

Creates new thread object which does not represent a thread.

my questions are:

  1. why do we need this constructor? And if we create a thread using this constructor, how can we "assign" a thread function later?
  2. Why don't we have a "run(function_address)" method so that when constructed with no parameter, we can specify a function to "run" for that thread.
  3. Or, we can construct a thread with a callable parameter(function, functors, etc.) but call a "run()" method to actually execute the thread later. Why std::thread is not designed in this way?

Aucun commentaire:

Enregistrer un commentaire