Let me preface this with the note that the whole idea behind what I'm trying to do is invoke an arbitrary function in a new thread, optionally delaying the invocation by some number of milliseconds
That said,
----- threadrun.h -----
#ifndef _THREADRUN_H_
#define _THREADRUN_H_
#include <boost/function.hpp>
namespace Thread
{
void ThreadRun(boost::function<void()> const &job);
void ThreadDelayedRun(boost::function<void()> const &job, unsigned int delay);
};
#endif
----- threadrun.h -----
----- threadrun.cpp -----
#include "threadrun.h"
static void DelayedRun(boost::function<void()> job, unsigned int delay)
{
Sleepms(delay); // Routine available elsewhere that simply sleeps for delay ms
job();
}
namespace Thread
{
void ThreadRun(boost::function<void()> const &job)
{
boost::thread thr = boost::thread(job);
thr.detach(); // Not really necessary, but it does make it explicit that we'll never wait for the thread to finish
}
void ThreadDelayedRun(boost::function<void()> const &job, unsigned int delay)
{
boost::thread thr = boost::thread(boost::bind(DelayedRun, job, delay));
thr.detach(); // Not really necessary, but it does make it explicit that we'll never wait for the thread to finish
}
};
----- threadrun.cpp -----