当前位置: 首页>>代码示例>>C++>>正文


C++ Thread::CreateThread方法代码示例

本文整理汇总了C++中Thread::CreateThread方法的典型用法代码示例。如果您正苦于以下问题:C++ Thread::CreateThread方法的具体用法?C++ Thread::CreateThread怎么用?C++ Thread::CreateThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Thread的用法示例。


在下文中一共展示了Thread::CreateThread方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: InitThreadPool

int Processor::InitThreadPool()
{
	/* Create @num threads for the thread pool. */
	assert(num > 0);

	for (int i = 0; i < num; i++) {
		Thread *t;
		ThreadLocalData *tld;

		t = new Thread;
		tld = new ThreadLocalData;
		memset(tld, 0, sizeof(*tld));
		tld->m = NULL;
		tld->p = this;
		tld->n = site;
		tld->t = t;
		tld->id = i;
		tld->flags = TLD_FROM_POOL;

		t->CreateThread(ProcessOneTask, tld);
		t->Insert(&idleQ);
		/* if (site)
			Print(NOW "Start [email protected]%d [email protected]%d for %s\n",
				now, i, t->GetPid(), site->GetDeviceName());*/
	}
	idle = num;
}
开发者ID:yingjinqian,项目名称:Lustre-Simulator,代码行数:27,代码来源:processor.cpp

示例2: AdjustThreadPool

int Processor::AdjustThreadPool(int c, int check)
{
	Thread * t;
	ThreadLocalData *tld;

	if (num == c)
		return rnum;

	num = c;
	if (rnum > c) { 
		/* First shrink the idle threads in the pool. */
		while (rnum > c) {
			t = NextIdleThreadFromPool();
			if (t == NULL)
				break;

			tld = t->GetTLD();
			delete t;
			delete tld;
			rnum--;
		}
		/*
		 * If there are some threads still in work state,
		 * release it once finishe the work.
		 */
		//num = c;
		LASSERT(idle >= 0);
		if (idle == 0)
			poolState = pool_FullLoadState;
	} else { /* add the new threads into the pool */
		while (rnum < c) {
			t = new Thread;
			tld = new ThreadLocalData;
			memset(tld, 0, sizeof(*tld));
			tld->m = NULL;
			tld->p = this;
			tld->n = site;
			tld->t = t;
			tld->id = counter++;
			tld->flags = TLD_FROM_POOL;

			t->CreateThread(ProcessOneTask, tld);
			t->Insert(&idleQ);
			rnum++;
			idle++;
		}
		if (poolState == pool_FullLoadState && idle > 0 && check) {
			Signal();
			poolState = pool_RunState;
		}
		
	}

	return rnum;
}
开发者ID:yingjinqian,项目名称:Lustre-Simulator,代码行数:55,代码来源:processor.cpp

示例3: OneRun

void PIOS:: OneRun(run_arg *args)
{
	Thread *t;
	ThreadLocalData *tld;

	args->fs = new FileSystem;
	t = new Thread;
	tld = new ThreadLocalData;
	memset(tld, 0, sizeof(*tld));
	tld->v = args;
	tld->t = t;

	Event::SetClock(0);

	args->fs->Start();
	t->CreateThread(do_one_run, tld);
	t->RunAfter(1);

	Event::Schedule();
	
	delete args->fs;
	delete tld;
	delete t;
}
开发者ID:yingjinqian,项目名称:Lustre-Simulator,代码行数:24,代码来源:pios.cpp

示例4: do_one_run

void PIOS::do_one_run(void *data)
{
	ThreadLocalData *tld = (ThreadLocalData *) data;
	run_arg *args = (run_arg *)tld->v;
	
	switch (tld->state) {
	case pios_RunOneStartState: {
		int i;

		args->startime = Event::Clock();
		Print(NOW "Start run: T %lu N %llu C %llu S %llu O %llu\n",
			args->startime, args->threadcount, args->regioncount,
			args->chunksize, args->regionsize, args->offset);

		/* Setup stream */
		args->streams = new pios_stream [args->regioncount];
		for (i = 0; i < args->regioncount; i++) {
			if (args->fpp) {
				args->streams[i].fid = i;
				args->streams[i].offset = args->offset;
				args->streams[i].max_offset = args->offset + args->regionsize;
				args->num_open_files++;
			} else {
				args->streams[i].fid = 0;
				args->streams[i].offset = args->offset * i;
				args->streams[i].max_offset = args->offset * i + args->regionsize;
			}
			args->streams[i].iotime = 0;
		}

		/* Setup pios thread data */
		args->ptds = new pios_thdata [args->threadcount];
		args->tlds = new ThreadLocalData [args->threadcount];

		memset(args->ptds, 0, sizeof(pios_thdata) * args->threadcount);
		memset(args->tlds, 0, sizeof(ThreadLocalData) * args->threadcount);
		for (i = 0; i < args->threadcount; i++) {
			Thread *t;

			t = new Thread;

			args->ptds[i].parent = tld->t;
			args->ptds[i].args = args;
			args->ptds[i].io.cmd = WRITE;
			args->ptds[i].io.count = 0;
			args->ptds[i].io.fid = 0;
			args->ptds[i].io.off = 0;
			args->ptds[i].io.waiter = t;
			args->ptds[i].io.left = 0;
			args->ptds[i].io.parent = NULL;
			args->ptds[i].io.ref = 0;

			args->tlds[i].t = t;
			args->tlds[i].id = i;
			args->tlds[i].f = do_one_thread;
			args->tlds[i].v = &args->ptds[i];
			args->tlds[i].flags |= TLD_CTX_SWITCH;
			t->CreateThread(do_one_thread, &args->tlds[i]);

			t->RunAfter(/*Event::Rand(args->threadcount * 10)*/1);
		}
		tld->state = pios_RunOneAllFinishState;
		break;
	}
	case pios_RunOneAllFinishState:
		args->iotime = Event::Clock() - args->startime;
		print_stats(args);
	case pios_RunOneLastState:
		/* cleanup all resource. */
		delete [] args->streams;
		delete [] args->ptds;
		delete [] args->tlds;
		break;
	}
}
开发者ID:yingjinqian,项目名称:Lustre-Simulator,代码行数:75,代码来源:pios.cpp


注:本文中的Thread::CreateThread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。