---
title: "ACE_Thread_Manager"
author: "glintstar"
date: "2009-05-15T10:19:39Z"
tags: []
slug: "ace-thread-manager"
draft: false
lastmod: "2009-05-15T10:24:19Z"
id: 387233
url: "https://glintstar.iteye.com/blog/387233"
---

//Spawn the first set of threads that work on task 1.

if(ACE_Thread_Manager::instance()->spawn_n(num_task_1,

(ACE_THR_FUNC)taskone,//Execute task one

0, //No arguments

THR_NEW_LWP, //New Light Weight Process

ACE_DEFAULT_THREAD_PRIORITY,

1)==-1) //Group ID is 1

ACE_ERROR((LM_ERROR,

"Failure to spawn first group of threads: %p \n"));

　

//Spawn second set of threads that work on task 2.

if(ACE_Thread_Manager::instance()->spawn_n(num_task_2,

(ACE_THR_FUNC)tasktwo,//Execute task one


在ACE中，TSS通过使用ACE_TSS模板类来实现。需要成为线程专有的类被传入ACE_TSS模板，然后可以使用C++的->操作符来调用它的全部公共方法。
ACE_TSS<DataType> data;
static void* thread1(void*)

{

data->set(10);

ACE_DEBUG((LM_DEBUG,"(%t)The value of data is %d \n",data->get()));

for(int i=0;i<5;i++)

data->increment();

ACE_DEBUG((LM_DEBUG,"(%t)The value of data is %d \n",data->get()));

return 0;

}

0, //No arguments

THR_NEW_LWP, //New Light Weight Process

ACE_DEFAULT_THREAD_PRIORITY,

2)==-1)//Group ID is 2

ACE_ERROR((LM_ERROR,

"Failure to spawn second group of threads: %p \n"));

　

//Wait for all tasks in grp 1 to exit

ACE_Thread_Manager::instance()->wait_grp(1);

ACE_DEBUG((LM_DEBUG,"Tasks in group 1 have exited! Continuing \n"));

　

//Wait for all tasks in grp 2 to exit

ACE_Thread_Manager::instance()->wait_grp(2);

　

ACE_DEBUG((LM_DEBUG,"Tasks in group 2 have exited! Continuing \n"));
**
thr_mgr->suspend_grp (grp_id)
thr_mgr->resume_grp (grp_id)
thr_mgr->resume_grp (grp_id) == -1
thr_mgr->wait ();**