• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pthread_setcancelstate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: LaunchThreadBalanceLength

 void* LaunchThreadBalanceLength(void* p_data) {
    /* Set up thread-safe buffers for this new thread */
    LOG.AddThreadSafeBuffer();
    LOGERR.AddThreadSafeBuffer();
    /* Make this thread cancellable */
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
    /* Get a handle to the thread launch data */
    CSpaceMultiThreadBalanceLength::SThreadLaunchData* psData = reinterpret_cast<CSpaceMultiThreadBalanceLength::SThreadLaunchData*>(p_data);
    /* Create cancellation data */
    SCleanupThreadData sCancelData;
    sCancelData.StartSenseControlPhaseMutex = &(psData->Space->m_tStartSenseControlPhaseMutex);
    sCancelData.StartActPhaseMutex = &(psData->Space->m_tStartActPhaseMutex);
    sCancelData.StartPhysicsPhaseMutex = &(psData->Space->m_tStartPhysicsPhaseMutex);
    sCancelData.StartMediaPhaseMutex = &(psData->Space->m_tStartMediaPhaseMutex);
    sCancelData.FetchTaskMutex = &(psData->Space->m_tFetchTaskMutex);
    pthread_cleanup_push(CleanupThread, &sCancelData);
    psData->Space->SlaveThread();
    /* Dispose of cancellation data */
    pthread_cleanup_pop(1);
    return NULL;
 }
开发者ID:alanmillard,项目名称:argos3,代码行数:22,代码来源:space_multi_thread_balance_length.cpp


示例17: memset

void *run_com(void *arg) {
	char response[512];
	char **tab = NULL;
	int size;

	memset(response, 0, 1024);

	fprintf(stderr, "thread com demarre :\n");

	/*--------------Blocquer les signaux------------------*/
	sigset_t mask;
	sigfillset(&mask);
	pthread_sigmask(SIG_SETMASK, &mask, NULL);

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

	while (TRUE) {
		read_response(sc, response);
		fprintf(stderr, "com: recu reponse len %zu : %s\n", strlen(response),
				response);

		if (0 == strlen(response)) {
			fprintf(stderr, "ERROR : Connection Socket");
			erreur("ERROR : Connection Socket", TRUE);
			break;
		}

		tab = string_to_arraystring(response, &size, '/');

		traitement(tab, size);

		/*free resources*/
		free_table(tab, size);
		memset(response, 0, sizeof(response));
	}
	pthread_cancel(thread_chat); //TODO
	return NULL;
}
开发者ID:naaf,项目名称:Master,代码行数:38,代码来源:main.c


示例18: tf1

static void *
tf1 (void *p)
{
  int err;

  if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) != 0
      || pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, NULL) != 0)
    {
      puts ("cannot set cancellation options");
      exit (1);
    }

  err = pthread_mutex_lock (&mut);
  if (err != 0)
    {
      puts ("child: cannot get mutex");
      exit (1);
    }

  err = pthread_barrier_wait (&bar);
  if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
    {
      printf ("barrier_wait returned %d\n", err);
      exit (1);
    }

  puts ("child: got mutex; waiting");

  pthread_cleanup_push (ch, NULL);

  pthread_cond_wait (&cond, &mut);

  pthread_cleanup_pop (0);

  puts ("child: cond_wait should not have returned");

  return NULL;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:38,代码来源:tst-cond8.c


示例19: receive

// Relay output from pru to stdout
void* receive(void* param) {
    int*            val;
    int             ready;
    FILE*           output;

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

    val = (int*)param;  //stupid, but compiler unhappy without this
    output = (FILE*)*val;
    if ((int)output == 1) output = stdout;

    // loop looking for output from pruss
    for(;;){
        ready = pruSharedMem_int[FROMPRU_F];
        if (ready != 0x00) {
            // check for special signal from pruss indicating a (re)start
            if (ready == 0x89abcdef) {
                if (quiet_mode) {
                    fprintf(output, "reset\n");                    
                } else {
                    fprintf(output, "Reset: %#8x\n", pruSharedMem_int[FROMPRU]);
                }
            } else {
                if (quiet_mode) {
                    fprintf(output, "%#8x\n", pruSharedMem_int[FROMPRU]);
                } else {
                    fprintf(output, "Got: %#8x\n", pruSharedMem_int[FROMPRU]);
                }
            }
            // acknowledge message
            pruSharedMem_int[FROMPRU_F] = 0x00;
        }
        // don't use all our cpu cycles
        usleep(RECEIVE_SLEEP);
    }
   pthread_exit(NULL);
} 
开发者ID:biocode3D,项目名称:prufh,代码行数:39,代码来源:prufh_term.c


示例20: pthread_setcancelstate

static void *limitMonitorTh(void *_)
{
    struct rusage usg;
    int peak_mem;
    float elapsed;

    // Enable cancelability and enable cancelation in sleep() call
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);

    while (1){
        borTimerStop(&limit_monitor.timer);
        elapsed = borTimerElapsedInSF(&limit_monitor.timer);
        if ((int)elapsed > limit_monitor.max_time){
            fprintf(stderr, "Aborting due to exceeded hard time limit"
                            " (elapsed %f, limit: %d.\n",
                    elapsed, limit_monitor.max_time);
            fflush(stderr);
            limitMonitorAbort();
            break;
        }

        if (getrusage(RUSAGE_SELF, &usg) == 0){
            peak_mem = usg.ru_maxrss / 1024L;
            if (peak_mem > limit_monitor.max_mem){
                fprintf(stderr, "Aborting due to exceeded hard mem limit"
                                " (peak-mem: %d, limit: %d).\n",
                        peak_mem, limit_monitor.max_mem);
                fflush(stderr);
                limitMonitorAbort();
                break;
            }
        }

        sleep(limit_monitor.sleeptime);
    }
    return NULL;
}
开发者ID:danfis,项目名称:maplan,代码行数:38,代码来源:search.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_setschedparam函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_setaffinity_np函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap