Opened 17 years ago

Closed 17 years ago

#16 closed Feature Requests (None)

way to defer thread creation needed

Reported by: nobody Owned by: nobody
Milestone: Component: thread
Version: None Severity:
Keywords: Cc:


It is not now currently possible to defer boost thread creation to a later time without creating a 
wrapper class for the thread class.  Starting a thread immediately in a constructor is not always 
desirable.  Sometimes you require other members in your class to be initialized before the thread, 
for example.  Or perhaps your class may have many threads that have to all be initialized before 
any of them can be created.  

I propose a new member function: thread::start(const function0<void>& threadfunc) to accomplish 
this goal.  To use this new function you could do something like:

   boost::thread thrd; // notice no function specified

or perhaps thread::start() could take no parameters and an new alternate thread constructor could 
be added that would not execute the thread right away:

   // thread class could have an enum { execute, defer } 
   boost::thread thrd(thread_alarm(secs), boost::thread::defer);

The latter form has the advantage of the caller of start() need not being concerned with what 
function is being invoked.  

Change History (1)

comment:1 Changed 17 years ago by bill_kempf

Status: assignedclosed
Logged In: YES 

There's no need for this type of functionality since 
boost::thread has no need for delayed initialization of 
data.  User data that needs to be delayed is already 
handled by the fact that the data and/or function object 
are seperate entities from the thread object.  Further, the 
suggested syntax won't work since the default constructor 
is already used for a different purpose.

If you don't understand how delayed initialization is 
already covered, please post a more specific question to 
the list.
Note: See TracTickets for help on using tickets.