2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-01 21:12:08 +00:00

Modified to use Boost.Function for the threadproc.

[SVN r10437]
This commit is contained in:
William E. Kempf
2001-06-26 19:20:11 +00:00
parent 1d6f10702d
commit 2febaf386c
5 changed files with 52 additions and 24 deletions

View File

@@ -48,7 +48,7 @@ public:
return buf;
}
static void do_sender_thread(void*)
static void do_sender_thread()
{
for (int n = 0; n < ITERS; ++n)
{
@@ -60,7 +60,7 @@ public:
}
}
static void do_receiver_thread(void*)
static void do_receiver_thread()
{
int n;
do
@@ -83,8 +83,8 @@ void do_test(M* dummy=0)
{
typedef buffer_t<M> buffer_type;
buffer_type::get_buffer();
boost::thread::create(&buffer_type::do_sender_thread, 0);
boost::thread::create(&buffer_type::do_receiver_thread, 0);
boost::thread::create(&buffer_type::do_sender_thread);
boost::thread::create(&buffer_type::do_receiver_thread);
boost::thread::join_all();
}

View File

@@ -63,7 +63,7 @@ private:
canteen g_canteen;
void chef(void*)
void chef()
{
const int chickens = 4;
{
@@ -139,15 +139,25 @@ struct thread_adapt
void* _param;
};
class thread_adapter
{
public:
thread_adapter(void (*func)(void*), void* param) : _func(func), _param(param) { }
void operator()() const { _func(_param); }
private:
void (*_func)(void*);
void* _param;
};
int main(int argc, char* argv[])
{
boost::thread::create(&chef, 0);
boost::thread::create(&chef);
phil p[] = { phil(0), phil(1), phil(2), phil(3), phil(4) };
boost::thread::create(&phil::do_thread, &p[0]);
boost::thread::create(&phil::do_thread, &p[1]);
boost::thread::create(&phil::do_thread, &p[2]);
boost::thread::create(&phil::do_thread, &p[3]);
boost::thread::create(&phil::do_thread, &p[4]);
boost::thread::create(thread_adapter(&phil::do_thread, &p[0]));
boost::thread::create(thread_adapter(&phil::do_thread, &p[1]));
boost::thread::create(thread_adapter(&phil::do_thread, &p[2]));
boost::thread::create(thread_adapter(&phil::do_thread, &p[3]));
boost::thread::create(thread_adapter(&phil::do_thread, &p[4]));
boost::thread::join_all();
return 0;
}

View File

@@ -67,12 +67,22 @@ struct thread_adapt
void* _param;
};
class thread_adapter
{
public:
thread_adapter(void (*func)(void*), void* param) : _func(func), _param(param) { }
void operator()() const { _func(_param); }
private:
void (*_func)(void*);
void* _param;
};
int main(int argc, char* argv[])
{
state = START;
boost::thread::create(&player, (void*)PLAYER_A);
boost::thread::create(&player, (void*)PLAYER_B);
boost::thread::create(thread_adapter(&player, (void*)PLAYER_A));
boost::thread::create(thread_adapter(&player, (void*)PLAYER_B));
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);