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


C++ pthread_setcancelstate函数代码示例

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


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

示例1: pthread_setcancelstate

/* _signal_handler - Process daemon-wide signals */
static void *_signal_handler(void *no_data)
{
	int rc, sig;
	int sig_array[] = {SIGINT, SIGTERM, SIGHUP, SIGABRT, 0};
	sigset_t set;

	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	(void) pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

	/* Make sure no required signals are ignored (possibly inherited) */
	_default_sigaction(SIGINT);
	_default_sigaction(SIGTERM);
	_default_sigaction(SIGHUP);
	_default_sigaction(SIGABRT);

	while (1) {
		xsignal_sigset_create(sig_array, &set);
		rc = sigwait(&set, &sig);
		if (rc == EINTR)
			continue;
		switch (sig) {
		case SIGHUP:	/* kill -1 */
			info("Reconfigure signal (SIGHUP) received");
			reconfig();
			break;
		case SIGINT:	/* kill -2  or <CTRL-C> */
		case SIGTERM:	/* kill -15 */
			info("Terminate signal (SIGINT or SIGTERM) received");
			shutdown_threads();
			return NULL;	/* Normal termination */
		case SIGABRT:	/* abort */
			info("SIGABRT received");
			abort();	/* Should terminate here */
			shutdown_threads();
			return NULL;
		default:
			error("Invalid signal (%d) received", sig);
		}
	}

}
开发者ID:adammoody,项目名称:slurm,代码行数:42,代码来源:slurmdbd.c

示例2: threadStarted

AREXPORT void *
ArRecurrentTask::runThread(void *ptr) 
{
  threadStarted();
#ifndef WIN32
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL);
#endif
  while (myRunning)
    {
      bool doit;

      while (myRunning)
	{
	  lock();
	  doit = go_req;
	  unlock();
	  if (doit)
	    break;
//	  yield();		// don't hog resources
#ifndef WIN32
	  usleep(10000);
#else
	  Sleep(10);
#endif
	}
      if (!myRunning)
	break;
      lock();
      go_req = false;
      running = true;		// we've been requested to go
      unlock();
      task();			// do what we've got to do...
      lock();
      running = false;		// say we're done
      unlock();
    }

  threadFinished();
  return NULL;
}
开发者ID:Aharobot,项目名称:ArAndroidApp,代码行数:41,代码来源:ArRecurrentTask.cpp

示例3: thread

// On entry, cancellation ought be disabled, and execution restricted to a
// single processor via hard affinity settings (FIXME: verify?).
static void *
thread(void *void_marshal){
	tguard *marshal = void_marshal;
	evhandler *ev = NULL;
	torque_ctx *ctx;

	ctx = marshal->ctx;
	if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL)){
		goto earlyerr;
	}
	if((ev = create_evhandler(&ctx->evq,&marshal->stack)) == NULL){
		goto earlyerr;
	}
	if(pthread_mutex_lock(&marshal->lock)){
		destroy_evhandler(ctx,ev);
		goto earlyerr;
	}
	if(marshal->ctx->ev == NULL){
		marshal->ctx->ev = ev;
	}else{
		ev->nexttid = marshal->ctx->ev->nexttid;
	}
	marshal->ctx->ev->nexttid = pthread_self();
	marshal->status = THREAD_STARTED;
	pthread_cond_broadcast(&marshal->cond);
	pthread_mutex_unlock(&marshal->lock);
	// After this point, anything we wish to use from marshal must've been
	// copied onto our own stack (hence broadcasting prior to unlocking).
	event_thread(ctx,ev);
	// Should never reach here (event_thread() is marked ((noreturn)))
	destroy_evhandler(ctx,ev);
	return NULL;

earlyerr:
	pthread_mutex_lock(&marshal->lock); // continue regardless
	marshal->status = THREAD_PREFAIL;
	pthread_cond_broadcast(&marshal->cond);
	pthread_mutex_unlock(&marshal->lock);
	destroy_evhandler(ctx,ev);
	return NULL;
}
开发者ID:dankamongmen,项目名称:libtorque,代码行数:43,代码来源:schedule.c

示例4: time

// ---------------------------------------------------------------------------
//
void *renderThreadLoop (void *data)
{
    wdTimers[WD_RENDER] = time (0);
    pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, 0);
    pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
    int ptErr = 0;

    for (;;)
    {
	LOCK (windowList.lock, ptErr);
	if (ptErr) die ("Error locking mutex");

        processWindows ();

	UNLOCK (windowList.lock, ptErr);
	if (ptErr) die ("Error unlocking mutex");

        wdTimers[WD_RENDER] = time (0);
        sleep (ctaConfig.arrLen);
    }
}
开发者ID:wwright2,项目名称:codeview,代码行数:23,代码来源:renderThread.c

示例5: pthread_setcancelstate

void* GRSServer::sendRoomService(void* obj){
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
    GRSServer *tempgr=(GRSServer *)obj;
    UdpServer *temp=tempgr->udps;
    string tis=tempgr->localName;
    tis.append("的房间");
    while (true) {
        pthread_testcancel();
        int res;
        char tbuffer[8];
        sockaddr_in remoteRecAddr;
        if ((res=temp->recvMsg(tbuffer,8,&remoteRecAddr))>0) {
            const char* sa=inet_ntoa(remoteRecAddr.sin_addr);
            string temps=tbuffer;
            const char* s=tis.c_str();
            temp->sendMsg(sa,s);
        }
    }
    return NULL;
}
开发者ID:00675901,项目名称:test_code,代码行数:21,代码来源:GRSServer.cpp

示例6: run_service

/* The main service loop.  It uses poll() to find things to act upon. */
void run_service (void) {
	int i;
	int polled;
	cbfree = NULL;
	errno = pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
	if (errno) {
		tlog (TLOG_UNIXSOCK | TLOG_DAEMON, LOG_ERR, "Service routine thread cancellability refused");
		exit (1);
	}
	for (i=0; i<1024; i++) {
		cblist [i].next = cbfree;
		cblist [i].fd = -1; // Mark as unused
		pthread_cond_init (&cblist [i].semaphore, NULL);
		cblist [i].followup = NULL;
		cbfree = &cblist [i];
	}
	tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Polling %d sockets numbered %d, %d, %d, ...", num_sox, soxpoll [0].fd, soxpoll [1].fd, soxpoll [2].fd);
	while (polled = poll (soxpoll, num_sox, -1), polled > 0) {
		tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Polled %d sockets, returned %d", num_sox, polled);
		for (i=0; i<num_sox; i++) {
			if (soxpoll [i].revents & (POLLHUP|POLLERR|POLLNVAL)) {
				int sox = soxpoll [i].fd;
				tlog (TLOG_UNIXSOCK, LOG_NOTICE, "Unregistering socket %d", sox);
				unregister_client_socket_byindex (i);
				close (sox);
				continue;
			} else if (soxpoll [i].revents) {
				tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Socket %d has revents=%d", soxpoll [i].fd, soxpoll [i].revents);
				process_activity (soxpoll [i].fd, i, &soxinfo [i], soxpoll [i].revents);
			}
		}
		tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Polling %d sockets numbered %d, %d, %d, ...", num_sox, soxpoll [0].fd, soxpoll [1].fd, soxpoll [2].fd);
	}
	if (stop_service) {
		tlog (TLOG_UNIXSOCK, LOG_NOTICE, "Service hangup in response to request");
	} else {
		tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Polled %d sockets, returned %d", num_sox, polled);
		perror ("Failed to poll for activity");
	}
}
开发者ID:vanrein,项目名称:tlspool,代码行数:41,代码来源:service.c

示例7: ThreadProc

void* ThreadProc(void* param)
#endif
{
    PSnapThread Thread;
    // Unix but not Solaris
#if (defined(POSIX) || defined(OS_OSX)) && (!defined(OS_SOLARIS))
    int last_type, last_state;
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &last_type);
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &last_state);
#endif
#ifdef OS_SOLARIS
#endif
    Thread = PSnapThread(param);

    if (!Thread->Terminated)
        try
        {
            Thread->Execute();
        } catch (...)
        {
        };
    Thread->Closed = true;
    if (Thread->FreeOnTerminate)
    {
        delete Thread;
    };
#ifdef OS_WINDOWS
    ExitThread(0);
#endif
#if defined(POSIX) && (!defined(OS_SOLARIS))
    pthread_exit((void*)0);
#endif
#if defined(OS_OSX)
    pthread_exit((void*)0);
#endif
#ifdef OS_SOLARIS
    thr_exit((void*)0);
#endif
    return 0; // never reach, only to avoid compiler warning
}
开发者ID:GermanBluefox,项目名称:ioBroker.s7,代码行数:40,代码来源:snap_threads.cpp

示例8: pthread_setcancelstate

// funzione realtiva allo spinlock
void *do_something(long int who_i_am) {
    int i;
    int dummy;

    // imposta la cancellazione asincrona
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,&dummy);
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&dummy);

    // aspetta che pure l'altro thread l'abbia fatto
    pthread_barrier_wait(&pbarrier);
    // sblocca il segnale SIGUSR1
    pthread_sigmask(SIG_UNBLOCK,&block_sig,NULL);

    while (1) {
        // selezione un intervallo casuale di tempo
        i=rand()%9+1;
        // avvisa
        printf("Thread %ld: going to sleep for %d sec...\n",who_i_am,i);
        // e dormi
        sleep(i);
        // prova ad acquisire lo spinlock
        if (pthread_spin_trylock(&spinlock)) {
            // in caso contrario avvisa
            printf("Thread %ld: wait for the spinlock...\n",who_i_am);
            // e attendi
            pthread_spin_lock(&spinlock);
        }
        // da qui ho acquisito lo spinlock
        // seleziona un intervallo casuale di tempo
        i=rand()%9+1;
        // avvisa
        printf("Thread %ld: spinlock obtained and now wait for %d sec...\n",who_i_am,i);
        // e dormi
        sleep(i);
        printf("Thread %ld: unlock spinlock...\n",who_i_am);
        // rilascia lo spinlock
        pthread_spin_unlock(&spinlock);
    }
    return NULL;
}
开发者ID:DesiD,项目名称:CsInfoPa,代码行数:41,代码来源:spinlock_cancel.c

示例9: _block_signals

static void *_start_routine(void *arg)
{
    thread_start_t *start = (thread_start_t *)arg;
    void *(*start_routine)(void *) = start->start_routine;
    void *real_arg = start->arg;
    thread_type *thread = start->thread;
    int detach = start->detached;

    _block_signals();

    free(start);

    /* insert thread into thread tree here */
    _mutex_lock(&_threadtree_mutex);
    thread->sys_thread = pthread_self();
    avl_insert(_threadtree, (void *)thread);
    _mutex_unlock(&_threadtree_mutex);

#ifdef THREAD_DEBUG
    LOG_INFO4("Added thread %d [%s] started at [%s:%d]", thread->thread_id, thread->name, thread->file, thread->line);
#endif

    if (detach) {
        pthread_detach(thread->sys_thread);
        thread->detached = 1;
    }
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

    /* call the real start_routine and start the thread
    ** this should never exit!
    */
    (start_routine)(real_arg);

#ifdef THREAD_DEBUG
    LOG_WARN("Thread x should never exit from here!!!");
#endif

    return NULL;
}
开发者ID:rektide,项目名称:dyne-muse,代码行数:39,代码来源:thread.c

示例10: threadEntrypoint

static void* threadEntrypoint(void* aArg)
{
#ifndef __ANDROID__
    int oldState;
    int status;
#endif
    ThreadData* data = (ThreadData*)aArg;
    assert(data != NULL);

#ifdef ATTEMPT_THREAD_PRIORITIES
    {
        TInt platMin = sched_get_priority_min(kThreadSchedPolicy);
        TInt platMax = sched_get_priority_max(kThreadSchedPolicy);
        // convert the UPnP library's 50 - 150 priority range into
        // an equivalent posix priority
        // ...calculate priority as percentage of library range
        int32_t percent = (((int32_t )data->iPriority - 50) * 100) / (150 - 50);
        // ...calculate native priority as 'percent' through the dest range
        int32_t priority = platMin + ((percent * (platMax - platMin))/100);
        sched_param param;
        param.sched_priority = priority;
        int status = pthread_setschedparam(data->iThread, kThreadSchedPolicy, &param);
        assert(status == 0);
    }
#endif // ATTEMPT_THREAD_PRIORITIES

    // Disable cancellation - we're in a C++ environment, and
    // don't want to rely on pthreads to mess things up for us.
#ifndef __ANDROID__
    status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
    assert(status == 0);
#endif

    //tlsThreadArg = data->iArg;
    pthread_setspecific(gThreadArgKey, data->iArg);
    data->iEntryPoint(data->iArg);

    return NULL;
}
开发者ID:astaykov,项目名称:ohNet,代码行数:39,代码来源:Os.c

示例11: th_wait

static void * th_wait(void *arg)
{
	proc_wt_t *wt = (proc_wt_t *)arg;
	pid_t w;
	int status;

	//pthread_cleanup_push(kill_pid, wt);

	status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	if (status != 0)
		printf("pthread_setcancelstate %d\n", status);

	do {
		w = waitpid(wt->pid, &status, WUNTRACED | WCONTINUED);
		if (w == -1) {
			wt->status |= PROC_S_ERR;
			perror("waitpid");
			goto out;
		}

		if (WIFEXITED(status)) {
			wt->status |= PROC_S_EXITED;
			printf("exited, status=%d\n", WEXITSTATUS(status));
		} else if (WIFSIGNALED(status)) {
			wt->status |= PROC_S_SIGNALED;
			printf("killed by signal %d\n", WTERMSIG(status));
		} else if (WIFSTOPPED(status)) {
			printf("stopped by signal %d\n", WSTOPSIG(status));
		} else if (WIFCONTINUED(status)) {
			printf("continued\n");
		}
	} while (!WIFEXITED(status) && !WIFSIGNALED(status));

out:
	pthread_cancel(wt->thr_timeout);
	//pthread_cleanup_pop(0);

	return NULL;
}
开发者ID:caiyuchao,项目名称:program,代码行数:39,代码来源:proc_timeout.c

示例12: pthread_setcancelstate

/* Function that the thread executes upon its creation */
void *a_thread_func()
{
	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);

	pthread_cleanup_push(a_cleanup_func,NULL);

	/* Indicate to main() that the thread has been created. */
	sem1=INMAIN;

	/* Wait until main() has sent out a cancel request, meaning until it
	 * sets sem1==INMAIN.  Sleeping for 3 secs. to give time for the
	 * cancel request to be sent and processed. */
	while (sem1==INMAIN)
		sleep(1);

	/* Should reach here if the thread correctly ignores the cancel
	 * request. */
	pthread_cleanup_pop(0);
	cleanup_flag=1;
	pthread_exit(0);
	return NULL;
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:23,代码来源:1-2.c

示例13: pthread_setcancelstate

void *pthread_1st(void *arg)
{
	#if 0
	int oldstate;
	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
	if(oldstate == PTHREAD_CANCEL_ENABLE)
		printf("it is enable before...\n");
	#endif

	#if 0
	int oldtype;
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
	if(oldtype == PTHREAD_CANCEL_DEFERRED)
		printf("it is deferrred...\n");
	#endif
	
	pthread_cleanup_push(cleanup_handle, NULL);
	//printf("%s(): The first thread...\n", __FUNCTION__);
	//fflush(stdout);
	
	while(1)
	{
		
		if(i == (2^32)/2-1)
			break;
		//printf("%s(): i %d\n", __FUNCTION__, i);
		//fflush(stdout);
		i++;
	}

	//sleep(1);
	//return;
	//pthread_testcancel();
	printf("I will exit...\n");
	fflush(stdout);
	pthread_exit((void *)22);
	pthread_cleanup_pop(0);
	//exit(1);
}
开发者ID:wolf623,项目名称:c_code,代码行数:39,代码来源:Process_c.c

示例14: lagopus_rwlock_leave_critical

lagopus_result_t
lagopus_rwlock_leave_critical(lagopus_rwlock_t *rwlptr) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;

  if (rwlptr != NULL &&
      *rwlptr != NULL) {
    int st;
    int oldstate;

    /*
     * The caller must have this rwlock locked.
     */
    oldstate = (*rwlptr)->m_prev_cancel_state;
    if (oldstate == PTHREAD_CANCEL_ENABLE ||
        oldstate == PTHREAD_CANCEL_DISABLE) {
      /*
       * This rwlock is locked via lagopus_rwlock_enter_critical().
       */
      if ((st = pthread_rwlock_unlock(&((*rwlptr)->m_rwl))) == 0) {
        if ((st = pthread_setcancelstate(oldstate, NULL)) == 0) {
          ret = LAGOPUS_RESULT_OK;
          pthread_testcancel();
        } else {
          errno = st;
          ret = LAGOPUS_RESULT_POSIX_API_ERROR;
        }
      } else {
        errno = st;
        ret = LAGOPUS_RESULT_POSIX_API_ERROR;
      }
    } else {
      ret = LAGOPUS_RESULT_CRITICAL_REGION_NOT_OPENED;
    }
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}
开发者ID:AkiraSuu,项目名称:lagopus,代码行数:39,代码来源:lock.c

示例15: H5TS_cancel_count_inc

/*--------------------------------------------------------------------------
 * NAME
 *    H5TS_cancel_count_inc
 *
 * USAGE
 *    H5TS_cancel_count_inc()
 *
 * RETURNS
 *    0 on success non-zero error code on error.
 *
 * DESCRIPTION
 *    Creates a cancelation counter for a thread if it is the first time
 *    the thread is entering the library.
 *
 *    if counter value is zero, then set cancelability type of the thread
 *    to PTHREAD_CANCEL_DISABLE as thread is entering the library and store
 *    the previous cancelability type into cancelation counter.
 *    Increase the counter value by 1.
 *
 * PROGRAMMER: Chee Wai LEE
 *            May 2, 2000
 *
 * MODIFICATIONS:
 *
 *    19 May 2000, Bill Wendling
 *    Changed function to return a value. Also changed the malloc() call to
 *    the H5MM_malloc() call and checked the returned pointer.
 *
 *--------------------------------------------------------------------------
 */
herr_t
H5TS_cancel_count_inc(void)
{
#ifdef  H5_HAVE_WIN_THREADS
    /* unsupported; just return 0 */
    return SUCCEED;
#else /* H5_HAVE_WIN_THREADS */
    H5TS_cancel_t *cancel_counter;
    herr_t ret_value = SUCCEED;

    cancel_counter = (H5TS_cancel_t *)H5TS_get_thread_local_value(H5TS_cancel_key_g);

    if (!cancel_counter) {
        /*
        * First time thread calls library - create new counter and associate
         * with key
         */
        cancel_counter = (H5TS_cancel_t *)H5MM_calloc(sizeof(H5TS_cancel_t));

        if (!cancel_counter) {
            H5E_push_stack(NULL, "H5TS_cancel_count_inc",
                           __FILE__, __LINE__, H5E_ERR_CLS_g, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed");
            return FAIL;
        }

        ret_value = pthread_setspecific(H5TS_cancel_key_g,
                                        (void *)cancel_counter);
    }

    if (cancel_counter->cancel_count == 0)
        /* thread entering library */
        ret_value = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,
                                           &cancel_counter->previous_state);

    ++cancel_counter->cancel_count;

    return ret_value;
#endif /* H5_HAVE_WIN_THREADS */
}
开发者ID:kidintwo3,项目名称:ExocortexCrate,代码行数:69,代码来源:H5TS.c


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