Modify

Opened 16 years ago

Closed 16 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:

Description

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
   thrd.start(thread_alarm(secs));

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);
   thrd.start();

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

Attachments (0)

Change History (1)

comment:1 Changed 16 years ago by bill_kempf

Status: assignedclosed
Logged In: YES 
user_id=180283

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain nobody.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.