#include "stdafx.h"
#include "ace/Synch.h"
#ifdef _DEBUG
#pragma comment(lib,"aced")
#else
#pragma comment(lib,"aced")
#endif
static int number=0;
static int seed=0;
#include "ace/Thread_Manager.h"
//static const int DEFAULT_THREADS = ACE_DEFAULT_THREADS;
//static const int DEFAULT_ITERATIONS = 100000;
static void *worker (int iterations)
{
ACE_OS::printf("ddd\n");
ACE_OS::sleep (1);
for (int i = 0; i < iterations; i++)
{
//ACE_DEBUG ((LM_DEBUG,"(%t) checking cancellation before iteration %d!\n", i));
//Before doing work check if you have been canceled. If so don’t
//do any more work.
if (ACE_Thread_Manager::instance ()->testcancel(ACE_Thread::self ()) != 0)
{//Worker函数中的每个线程将使用ACE_Thread_Manager的testcancel()来检查取消情况
//ACE_DEBUG ((LM_DEBUG,"(%t) has been canceled before iteration %d!\n",i));
break;
}
ACE_OS::printf("循环次数\n");
}
return 0;
}
int main (int argc, char *argv[])
{
int n_threads = 1;
int n_iterations = 10;
ACE_Thread_Manager *thr_mgr = ACE_Thread_Manager::instance ();
//Create a group of threads n_threads that will execute the worker
//function the spawn_n method returns the group ID for the group of
//threads that are spawned. The argument n_iterations is passed back
//to the worker. Notice that all threads are created detached.
int grp_id = thr_mgr->spawn_n (n_threads, ACE_THR_FUNC (worker),(void *) n_iterations,THR_NEW_LWP | THR_DETACHED);
// Wait for 1 second and then suspend every thread in the group.
ACE_OS::sleep (1);
//ACE_DEBUG ((LM_DEBUG, "(%t) suspending group\n"));
if (thr_mgr->suspend_grp (grp_id) == -1)//挂起
{
ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "Could not suspend_grp"));
}
// Wait for 1 more second and then resume every thread in the
// group.
ACE_OS::sleep (5);
//ACE_DEBUG ((LM_DEBUG, "(%t) resuming group\n"));
if (thr_mgr->resume_grp (grp_id) == -1)//恢复
{
ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "resume_grp"));
}
// Wait for 1 more second and then cancel all the threads.
//ACE_DEBUG ((LM_DEBUG, "(%t) canceling group\n"));
if (thr_mgr->cancel_grp (grp_id) == -1)//取消
{
ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "cancel_grp"));
}
// Perform a barrier wait until all the threads have shut down.
thr_mgr->wait ();
return 0;
}
liforgetbain
- 粉丝: 0
- 资源: 1
最新资源
- 形状分类31-YOLO(v5至v11)、COCO、CreateML、Darknet、Paligemma、VOC数据集合集.rar
- 常见排序算法概述及其性能比较
- 前端开发中的JS快速排序算法原理及实现方法
- 基于Java的环境保护与宣传网站论文.doc
- 基于8086的电子琴程序Proteus仿真
- 基于java的二手车交易网站的设计和实现论文.doc
- 纯真IP库,用于ip查询地址使用的数据库文件
- 基于javaweb的动漫网站管理系统毕业设计论文.doc
- 废物垃圾检测28-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- 探索CSDN博客数据:使用Python爬虫技术
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈