您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ thr_create函数代码示例

51自学网 2021-06-03 08:48:21
  C++
这篇教程C++ thr_create函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中thr_create函数的典型用法代码示例。如果您正苦于以下问题:C++ thr_create函数的具体用法?C++ thr_create怎么用?C++ thr_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

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

示例1: main

main(){  int i;  struct sigaction act;  act.sa_handler = ExitHandler;  (void) sigemptyset(&act.sa_mask);  (void) sigaction(SIGTERM, &act, NULL);   mutex_init(&first_mutex, 0 , 0);  mutex_init(&second_mutex, 0 , 0);  main_thread = thr_self();  thr_create(NULL,0,first_thread,0,THR_NEW_LWP,&one_tid);  thr_create(NULL,0,second_thread,0,THR_NEW_LWP,&two_tid);   for (i = 0; i < 10; i++){    fprintf(stderr, "main loop: %d/n", i);    if (i == 5)	{      thr_kill(one_tid, SIGTERM);    }    sleep(3);  }  thr_kill(two_tid, SIGTERM);  sleep(5);  fprintf(stderr, "main exit/n");}
开发者ID:vezril,项目名称:programming_oldstuff,代码行数:28,


示例2: inc_count

/** @brief The workhorse thread of the test. * *  This thread recursively spawns two copies of itself decrementing n_voidstar *  so long as n_voidstar is positive. Each thread repeats this process n_throws *  times, after joining on the threads it created. * *  @param The level we are at (to keep us from infinitly recursively spawning. */void *juggle(void * n_voidstar){    int sub1, sub2;    int throws;    int substat;    int ret;    int n = (int)n_voidstar;    inc_count();    print_count(n);    if (n > 0) {        for (throws = 0; throws < n_throws; throws++) {                // Toss up two balls            sub1 = thr_create(juggle, (void *)(n - 1));                    if (sub1 < 0) {                lprintf("Lev %d failed to create first thread w/ err %d/n",                        n, sub1);            }                sub2 = thr_create(juggle, (void *)(n - 1));                if (sub2 < 0) {                lprintf("Lev %d failed to create second thread w/ err %d/n",                        n, sub2);            }                // Try to catch them            if ((ret = thr_join(sub1, (void*)&substat))                 != 0 || substat != (n - 1)) {              lprintf("Lev %d failed to join first thread correctly:/n/t", n);              lprintf("join(%d), ret = %d, %d ?= %d/n",                                    sub1, ret, (n - 1), substat);            }                        if ((ret = thr_join(sub2, (void*)&substat))                != 0 || substat != (n - 1)) {              lprintf("Lev %d failed to join second thread correctly:/n/t", n);              lprintf("join(%d), ret = %d, %d ?= %d/n",                                    sub2, ret, (n - 1), substat);            }        }    }#ifdef PRINT    // Tell that we were successfull.    putchar((char)n + '0');#endif    print_count(n);    // Hang in the air for some amount of time    sleep(genrand() % SLEEP_MAX);        return (void *)n;}
开发者ID:xiaozhuyfk,项目名称:Pebble_Kernel,代码行数:65,


示例3: thread_work

voidthread_work(){	int i;#ifdef UNBOUND    #ifdef SOLARIS	if (thr_setconcurrency(nthreads) != 0) {		perror("Oops, thr_setconcurrency failed");		exit(1);	}    #endif#endif	/* create nthreads threads, having each start at do_work */	for (i = 0; i < nthreads; i++) {		int retval;#ifdef SOLARIS    #ifdef BOUND		retval = thr_create(0, 0, do_work, 0, THR_BOUND, &(tid[i]));    #endif    #ifdef UNBOUND		retval = thr_create(0, 0, do_work, 0, 0, &(tid[i]));    #endif#endif#ifdef POSIX    #ifdef BOUND		retval = pthread_create(&(tid[i]), &attr, do_work, 0);    #endif    #ifdef UNBOUND		retval = pthread_create(&(tid[i]), 0, do_work, 0);    #endif#endif		if(retval != 0) {			perror("Oops, thr_create failed");			exit(1);		}	}	/* wait for all threads to complete their work and join */	for (i = 0; i < nthreads; i++) {#ifdef SOLARIS		thr_join(tid[i], 0, 0);#endif#ifdef POSIX		pthread_join(tid[i], 0);#endif	}}
开发者ID:dhaley,项目名称:dcp,代码行数:51,


示例4: main

main (int argc, char *argv[]){  int ncorr, t1arg, t0arg, orig_ncorr;  thread_t tid1, tid0;  float rate;  if (argc != 6)    {      printf ("usage: %s t0_bound t0_new_lwp t1_bound t1_new_lwp ncorr/n", argv[0]);      exit (1);    }  t0arg = THR_DETACHED;  if (atoi (argv[1]))    t0arg |= THR_BOUND;  if (atoi (argv[2]))    t0arg |= THR_NEW_LWP;  t1arg = THR_DETACHED;  if (atoi (argv[3]))    t1arg |= THR_BOUND;  if (atoi (argv[4]))    t1arg |= THR_NEW_LWP;  ncorr = atoi (argv[5]);  if (thr_create (0, 0, work, 0, t0arg, &tid0) != 0)    perror ("couldn't create thread 0");  if (thr_create (0, 0, work, (void *) 1, t1arg, &tid1) != 0)    perror ("couldn't create thread 1");  orig_ncorr = thr_getconcurrency ();  if (ncorr)    thr_setconcurrency (ncorr);  sleep (NSLEEP);  rate = (count[0] + count[1]) / ((float) NSLEEP);    printf ("/n------------------------------------------------------------------------/n");  printf ("t0arg 0x%x (%s, %s, %s)/nt1arg 0x%x (%s, %s, %s)/ncount[0] %d count[1] %d/n/           ncorr_orig %d ncorr_set %d ncorr_end %d rate %.3f per_cxt %.2f usec/n",          t0arg,          (t0arg & THR_DETACHED) ? "THR_DETACHED" : "Not Detached",          (t0arg & THR_BOUND) ? "THR_BOUND" : "Not Bound",          (t0arg & THR_NEW_LWP) ? "THR_NEW_LWP" : "No New_LWP",          t1arg,          (t1arg & THR_DETACHED) ? "THR_DETACHED" : "Not Detached",          (t1arg & THR_BOUND) ? "THR_BOUND" : "Not Bound",          (t1arg & THR_NEW_LWP) ? "THR_NEW_LWP" : "No New_LWP",          count[0], count[1],          orig_ncorr, ncorr, thr_getconcurrency (), rate, 1.0e6 / rate);}
开发者ID:CCJY,项目名称:ACE,代码行数:49,


示例5: main

int main( int argc, char *argv[] ){    int i, err;    switch(argc) {        case 6:            i = atoi(argv[5]);            if(i >= 0)                bad_sleep = i;        case 5:            i = atoi(argv[4]);            if(i >= 0)                pause = i;        case 4:            i = atoi(argv[3]);            if(i > 0)                sems = i;        case 3:            i = atoi(argv[2]);            if(i <= 26 && i > 0)                run = i;        case 2:            i = atoi(argv[1]);            if(i > 1 || i <= 24)                threads = i;        default:            break;    }    expect(thr_init(STACK_SIZE));    expect(mutex_init(&lock_print));    expect(mutex_init(&lock_running));    expect(sem_init(&sem, sems));    for(i=0; i<80; i++)        empty[i] = ' ';    empty[80] = '/0';       expect(thr_create(bad, (void*)i) >= 0);        for(i=0; i<threads; i++)        expect(thr_create(race, (void*)i) >= 0);        getchar();    expect(set_cursor_pos(24,0));        task_vanish(0);}
开发者ID:Jarvishappy,项目名称:p2-1,代码行数:48,


示例6: umem_create_update_thread

intumem_create_update_thread(void){#ifndef _WIN32	sigset_t sigmask, oldmask;#endif	ASSERT(MUTEX_HELD(&umem_update_lock));	ASSERT(umem_update_thr == 0);#ifndef _WIN32	/*	 * The update thread handles no signals	 */	(void) sigfillset(&sigmask);	(void) thr_sigsetmask(SIG_BLOCK, &sigmask, &oldmask);#endif	if (thr_create(NULL, 0, umem_update_thread, NULL,	    THR_BOUND | THR_DAEMON | THR_DETACHED, &umem_update_thr) == 0) {#ifndef _WIN32		(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);#endif		return (1);	}	umem_update_thr = 0;#ifndef _WIN32	(void) thr_sigsetmask(SIG_SETMASK, &oldmask, NULL);#endif	return (0);}
开发者ID:YaroslavLitvinov,项目名称:zfs-prezerovm,代码行数:30,


示例7: MPIU_Thread_create

/* * MPIU_Thread_create() */void MPIU_Thread_create(MPIU_Thread_func_t func, void * data, MPIU_Thread_id_t * idp, int * errp){    struct MPEI_Thread_info * thread_info;    int err = MPIU_THREAD_SUCCESS;    /* FIXME: faster allocation, or avoid it all together? */    thread_info = (struct MPEI_Thread_info *) MPIU_Malloc(sizeof(struct MPEI_Thread_info));    if (thread_info != NULL)    {        thread_info->func = func;        thread_info->data = data;        err = thr_create(NULL, 0, MPEI_Thread_start, thread_info, THR_DETACHED, idp);        /* FIXME: convert error to an MPIU_THREAD_ERR value */    }    else    {        err = 1000000000;    }    if (errp != NULL)    {        *errp = err;    }}
开发者ID:adevress,项目名称:MPICH-BlueGene,代码行数:28,


示例8: doit

/* * Fire off a detached thread for each host in the list, if the thread * create fails simply run synchronously. */static voiddoit(char *hostname){	thread_t tid;	char *thread_hostname;	(void) mutex_lock(&thr_mtx);	while (thread_count >= MAX_THREADS) {		(void) mutex_unlock(&thr_mtx);		(void) sleep(PATIENCE/2);		(void) mutex_lock(&thr_mtx);	}	thread_count++;	(void) mutex_unlock(&thr_mtx);	thread_hostname = strdup(hostname);	if (thread_hostname == (char *)NULL) {		(void) mutex_lock(&tty);		(void) fprintf(stderr, "Ran out of memory/n");		(void) mutex_unlock(&tty);		exit(1);	}	if (thr_create(NULL, 0, do_one, thread_hostname,			THR_DETACHED, &tid) != 0) {		(void) do_one(thread_hostname);	}}
开发者ID:andreiw,项目名称:polaris,代码行数:33,


示例9: start_register_monitor

void start_register_monitor(const char *name, volatile U32 *addr,			    int x, int y, unsigned width, unsigned height,			    Window root, GC labelgc, GC boxgc,			    int bgPixel, int dgPixel){  thread_t monitor_thread;  struct regmon_args *regmon_args;  if ((regmon_args = (struct regmon_args *)malloc(sizeof(struct regmon_args)))) {    regmon_args->label = name;    regmon_args->addr = addr;    regmon_args->x = x;    regmon_args->y = y;    regmon_args->width = width;    regmon_args->height = height;    regmon_args->root = root;    regmon_args->labelgc = labelgc;    regmon_args->boxgc = boxgc;    regmon_args->backgroundPixel = bgPixel;    regmon_args->shadowPixel = dgPixel;    thr_create(NULL, 0, register_monitor_main, (void *)regmon_args,	       THR_DETACHED | THR_DAEMON, &monitor_thread);  }}
开发者ID:grubba,项目名称:LMTAE,代码行数:25,


示例10: _nscd_init_getent_ctx_monitor

static nscd_rc_t_nscd_init_getent_ctx_monitor() {    int	errnum;    char	*me = "_nscd_init_getent_ctx_monitor";    _NSCD_LOG(NSCD_LOG_GETENT_CTX, NSCD_LOG_LEVEL_DEBUG)    (me, "initializing the getent context monitor/n");    /*     * the forker nscd does not process getent requests     * so no need to monitor orphan getent contexts     */    if (_whoami == NSCD_FORKER)        return (NSCD_SUCCESS);    /*     * start a thread to reclaim unused getent contexts     */    if (thr_create(NULL, NULL, reclaim_getent_ctx,                   NULL, THR_DETACHED, NULL) != 0) {        errnum = errno;        _NSCD_LOG(NSCD_LOG_GETENT_CTX, NSCD_LOG_LEVEL_ERROR)        (me, "thr_create: %s/n", strerror(errnum));        return (NSCD_THREAD_CREATE_ERROR);    }    return (NSCD_SUCCESS);}
开发者ID:mikess,项目名称:illumos-gate,代码行数:29,


示例11: sub_c

void * sub_c(void *arg){void *status;int i;thread_t main_thr, ret_thr;main_thr = (thread_t)arg;printf("C: In thread C.../n"); if (thr_create(NULL, 0, sub_f, (void *)0, THR_BOUND|THR_DAEMON, NULL))        fprintf(stderr, "Can't create thr_f/n"), exit(1);printf("C: Join main thread/n"); if (thr_join(main_thr,(thread_t *)&ret_thr, &status))         fprintf(stderr, "thr_join Error/n"), exit(1);printf("C: Main thread (%d) returned thread (%d) w/status %d/n", main_thr, ret_thr, (int) status); /* process */for (i=0;i<1000000*(int)thr_self();i++);printf("C: Thread exiting.../n"); thr_exit((void *)88);}
开发者ID:jindal25,项目名称:Coding4cpp,代码行数:27,


示例12: taskq_create

/*ARGSUSED*/taskq_t *taskq_create(const char *name, int nthreads, pri_t pri,	int minalloc, int maxalloc, uint_t flags){	taskq_t *tq = kmem_zalloc(sizeof (taskq_t), KM_SLEEP);	int t;	rw_init(&tq->tq_threadlock, NULL, RW_DEFAULT, NULL);	tq->tq_flags = flags | TASKQ_ACTIVE;	tq->tq_active = nthreads;	tq->tq_nthreads = nthreads;	tq->tq_minalloc = minalloc;	tq->tq_maxalloc = maxalloc;	tq->tq_task.task_next = &tq->tq_task;	tq->tq_task.task_prev = &tq->tq_task;	tq->tq_threadlist = kmem_alloc(nthreads * sizeof (thread_t), KM_SLEEP);	if (flags & TASKQ_PREPOPULATE) {		mutex_enter(&tq->tq_lock);		while (minalloc-- > 0)			task_free(tq, task_alloc(tq, KM_SLEEP));		mutex_exit(&tq->tq_lock);	}	for (t = 0; t < nthreads; t++)		(void) thr_create(0, 0, taskq_thread,		    tq, THR_BOUND, &tq->tq_threadlist[t]);	return (tq);}
开发者ID:BjoKaSH,项目名称:mac-zfs,代码行数:31,


示例13: main

void main(int argc, char** argv){	if (argc != 3 )    {		cerr <<"Usage " << argv[0]<< "<BUF_SIZE> < # of THREAD>"<<endl;		return;    }	long flag = THR_DETACHED|THR_NEW_LWP;	MemRegisterTask();	new int;	MemInitDefaultPool();	MEM_POOL_INFO info;	MemPoolInfo(MemDefaultPool, NULL, &info);	printf("def pool pageSize: %d;"     "blockSizeFS: %hd/n",     info.pageSize, info.blockSizeFS);	long long buf_size = atoll(argv[1]);	int no_of_threads = atoi(argv[2]);	thread_t t1;    for(int i=0;i<no_of_threads;i++)    {	    thr_create(NULL,0,thr_RUN,(void*)&buf_size,flag, &t1);    }    while (thr_join(NULL, NULL, NULL)==0);	return;}
开发者ID:pp7462-git,项目名称:sandbox,代码行数:32,


示例14: HAE_CreateFrameThread

// Create and start the frame threadint HAE_CreateFrameThread(void* context, HAE_FrameThreadProc proc){    if (proc)	{	    long	error;	    theFrameProc = proc;	    error = thr_create(NULL, NULL, PV_NativeFrameThreadProc, NULL,			       THR_BOUND | THR_NEW_LWP,			       &theFrameThread);	    if (error == 0) 		{		    error = thr_setprio(theFrameThread, 127);		    if (error == 0)			{			    return 0;			}		    else			{			    DEBUG_STR("Failure to set priority of Solaris thread/n");			}		}	    else		{		    DEBUG_STR("Failure to create Solaris thread/n");		}	    theFrameProc = NULL;	}    return -1;}
开发者ID:fatman2021,项目名称:myforthprocessor,代码行数:31,


示例15: create_listen_thread

/* create listen thread */static boolean_tcreate_listen_thread(vntsd_group_t *groupp){	char err_msg[VNTSD_LINE_LEN];	int rv;	assert(groupp);	(void) mutex_lock(&groupp->lock);	assert(groupp->num_cons);	D1(stderr, "[email
C++ thr_self函数代码示例
C++ thr函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。