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


C++ pthread_attr_setinheritsched函数代码示例

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


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

示例1: thread_create

Thread_t thread_create(int prio, int sched, ThreadFunc_t func, void *arg)
{
#define n_static 256
  static struct ThreadArgs args_hack[n_static];
  static unsigned hack_idx = 0;
  struct ThreadArgs *args = &args_hack[hack_idx++%n_static];  
#undef n_static
  pthread_t thr;
  pthread_attr_t attr;
#ifndef __KERNEL__
  if (sched == Default && geteuid() == 0) sched = RR;
  else if (sched == Default) sched = Other;
#else
  if (sched == Default) sched = RR;
#endif
  if (prio < thread_prio_min(sched)) prio = thread_prio_min(sched);
  if (prio > thread_prio_max(sched)) prio = thread_prio_max(sched);
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  if (sched != Inherit) {
    struct sched_param sp;
    sched = scheduler_translate(sched);
    pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr, sched);
    sp.sched_priority = prio;
    pthread_attr_setschedparam(&attr, &sp);
  } else if (sched == Inherit) {
    pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
  }
#ifdef RTLINUX
  pthread_attr_setfp_np(&attr, 1);
#endif
  args->func = func;
  args->arg = arg;
  (void) prio; /* TODO: implement priorities.. */
  if (pthread_create(&thr, &attr, thread_wrapper, args)) 
    /* TODO handle errors here.. */
    return NULL;
  pthread_attr_destroy(&attr);
  return (Thread_t)thr;
}
开发者ID:ruby6117,项目名称:ccode,代码行数:41,代码来源:SysDep.c

示例2: pthread_attr_setinheritsched

/**
 *  Starts the thread. This method will signal to start the thread and
 *  return immediately. Note that the thread might not yet run when this
 *  method returns! The abstract method Main() is the entry point for the
 *  new thread. You have to implement the Main() method in your subclass.
 *
 *  @see StartThread()
 */
int Thread::SignalStartThread() {
    // prepare the thread properties
    int res = pthread_attr_setinheritsched(&__thread_attr, PTHREAD_EXPLICIT_SCHED);
    if (res) {
        std::cerr << "Thread creation failed: Could not inherit thread properties."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    res = pthread_attr_setdetachstate(&__thread_attr, PTHREAD_CREATE_JOINABLE);
    if (res) {
        std::cerr << "Thread creation failed: Could not request a joinable thread."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    res = pthread_attr_setscope(&__thread_attr, PTHREAD_SCOPE_SYSTEM);
    if (res) {
        std::cerr << "Thread creation failed: Could not request system scope for thread scheduling."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    res = pthread_attr_setstacksize(&__thread_attr, MIN_STACK_SIZE);
    if (res) {
        std::cerr << "Thread creation failed: Could not set minimum stack size."
                  << std::endl << std::flush;
        RunningCondition.Set(false);
        return res;
    }
    // Create and run the thread
    res = pthread_create(&this->__thread_id, &__thread_attr, __pthread_launcher, this);
    switch (res) {
        case 0: // Success
            break;
        case EAGAIN:
            std::cerr << "Thread creation failed: System doesn't allow to create another thread."
                      << std::endl << std::flush;
            RunningCondition.Set(false);
            break;
        case EPERM:
            std::cerr << "Thread creation failed: You're lacking permisssions to set required scheduling policy and parameters."
                      << std::endl << std::flush;
            RunningCondition.Set(false);
            break;
        default:
            std::cerr << "Thread creation failed: Unknown cause."
                      << std::endl << std::flush;
            RunningCondition.Set(false);
            break;
    }
    return res;
}
开发者ID:svn2github,项目名称:linuxsampler,代码行数:61,代码来源:Thread.cpp

示例3: start_interrupt_source

int start_interrupt_source( int intr )
{
    pthread_attr_t      pattr;
    struct sched_param  param;

    pthread_attr_init( &pattr );
    param.sched_priority = 15;
    pthread_attr_setschedparam( &pattr, &param );
    pthread_attr_setinheritsched( &pattr, PTHREAD_EXPLICIT_SCHED );

    return pthread_create( NULL, NULL, interrupt_thread, (void *)intr );
}
开发者ID:vocho,项目名称:openqnx,代码行数:12,代码来源:sources.c

示例4: main

int main()
{
	pthread_t new_th;
	pthread_attr_t attr;
	int rc;
	struct sched_param sp;

	/* Initialize attr */
	rc = pthread_attr_init(&attr);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_init");
		exit(PTS_UNRESOLVED);
	}

	rc = pthread_attr_setschedpolicy(&attr, policy);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_setschedpolicy");
		exit(PTS_UNRESOLVED);
	}

	sp.sched_priority = 1;
	rc = pthread_attr_setschedparam(&attr, &sp);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_setschedparam");
		exit(PTS_UNRESOLVED);
	}

	int insched = PTHREAD_EXPLICIT_SCHED;
	rc = pthread_attr_setinheritsched(&attr, insched);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_setinheritsched");
		exit(PTS_UNRESOLVED);
	}

	rc = pthread_create(&new_th, &attr, thread_func, NULL);
	if (rc != 0) {
		printf("Error at pthread_create(): %s\n", strerror(rc));
		exit(PTS_UNRESOLVED);
	}

	rc = pthread_join(new_th, NULL);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_join");
		exit(PTS_UNRESOLVED);
	}
	rc = pthread_attr_destroy(&attr);
	if (rc != 0) {
		printf(ERROR_PREFIX "pthread_attr_destroy");
		exit(PTS_UNRESOLVED);
	}
	printf("Test PASSED\n");
	return PTS_PASS;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:53,代码来源:2-2.c

示例5: start_timer_source

int start_timer_source( void )
{
    pthread_attr_t      pattr;
    struct sched_param  param;

    pthread_attr_init( &pattr );
    param.sched_priority = 10;
    pthread_attr_setschedparam( &pattr, &param );
    pthread_attr_setinheritsched( &pattr, PTHREAD_EXPLICIT_SCHED );

    return pthread_create( NULL, &pattr, timer_thread, NULL );
}
开发者ID:vocho,项目名称:openqnx,代码行数:12,代码来源:sources.c

示例6: startThread

int startThread(Thread* thrd)
{
	struct sched_param schedp;
	pthread_condattr_t condattr;
	int retc, policy, inherit;

	printf("Start thread priority %d\n", thrd->priority);
	if (pthread_attr_init(&(thrd->attr)) != 0) {
		printf("Attr init failed");
		exit(2);
	}
	thrd->flags = 0;
	memset(&schedp, 0, sizeof(schedp));
	schedp.sched_priority = thrd->priority;
	policy = thrd->policy;

	if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
		printf("Can't set policy %d\n", policy);
	}
	if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
		printf("Can't get policy\n");
	} else {
		printf("Policy in attribs is %d\n", policy);
	}
	if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
		printf("Can't set params");
	}
	if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
		printf("Can't get params");
	} else {
		printf("Priority in attribs is %d\n", schedp.sched_priority);
	}
	if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) != 0) {
		printf("Can't set inheritsched\n");
	}
	if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
		printf("Can't get inheritsched\n");
	} else {
		printf("inherit sched in attribs is %d\n", inherit);
	}
	if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
		printf("Failed to init mutex: %d\n", retc);
	}
	if (pthread_condattr_init(&condattr) != 0) {
		printf("Failed to init condattr\n");
	}
	if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
		printf("Failed to init cond\n");
	}
	retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
	printf("Create returns %d\n\n", retc);
	return retc;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:53,代码来源:testpi-3.c

示例7: sizeof

thread_type *thread_create_c(char *name, void *(*start_routine)(void *),
        void *arg, int detached, int line, char *file)
{
    int ok = 1;
    thread_type *thread = NULL;
    thread_start_t *start = NULL;
    pthread_attr_t attr;

    thread = (thread_type *)acalloc(1, sizeof(thread_type));
    do {
        start = (thread_start_t *)acalloc(1, sizeof(thread_start_t));
        if (pthread_attr_init (&attr) < 0)
            break;

        thread->line = line;
        thread->file = strdup(file);

        _mutex_lock (&_threadtree_mutex);
        thread->thread_id = _next_thread_id++;
        _mutex_unlock (&_threadtree_mutex);

        thread->name = strdup(name);
        thread->create_time = time(NULL);

        start->start_routine = start_routine;
        start->arg = arg;
        start->thread = thread;

        pthread_attr_setstacksize (&attr, 512*1024);
        pthread_attr_setinheritsched (&attr, PTHREAD_INHERIT_SCHED);
        if (detached)
        {
            pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
            thread->detached = 1;
        }

        if (pthread_create (&thread->sys_thread, &attr, _start_routine, start) == 0)
        {
            pthread_attr_destroy (&attr);
            return thread;
        }
        else
            pthread_attr_destroy (&attr);
    }
    while (0);

#ifdef THREAD_DEBUG
    LOG_ERROR("Could not create new thread %s", name);
#endif
    if (start) free (start);
    if (thread) free (thread);
    return NULL;
}
开发者ID:xaiki,项目名称:IceCast,代码行数:53,代码来源:thread.c

示例8: main

int main(int argc, char* argv[])
{
    //pthread_t threads[4];
    printf("Start des Beispiels \n");
    //printf("Argumente verfuegbar: ARGC\n", 3*argc);
    p_rb -> p_in = p_start;
    p_rb -> p_out = p_start;
    p_rb -> count = 0;
    printf("Counter value %d\n", p_rb ->count);

    pthread_attr_t my_thread_attr; // Thread Attribut
    struct sched_param my_prio;
    pthread_attr_init(&my_thread_attr);
    pthread_attr_setinheritsched(&my_thread_attr, PTHREAD_EXPLICIT_SCHED); // Freigabe der Parameteränd.
    pthread_attr_setschedpolicy(&my_thread_attr, SCHED_FIFO);
    my_prio.sched_priority = 10; // Priority ändern
    pthread_attr_setschedparam(&my_thread_attr, &my_prio);

    // Threads erstellen
    pthread_create(&threads[2], NULL, control, (void *)&thread_id[2]);
    pthread_create(&threads[0], NULL, p_1_w, (void *)thread_id);
    pthread_create(&threads[1], NULL, p_2_w, (void *)&thread_id[1]);
    pthread_create(&threads[3], NULL, consumer, (void *)&thread_id[3]);

        // Controller join und status abfangen
        pthread_join(threads[2], &status);
        // Wenn erfolgreich beendet
        if (status == 0) {
            printf("Control join erfolgreich!\n");
            pthread_cond_signal(&p1_unlock); // signal für das Freigeben, wenn p1 gestoppt ist.
            pthread_cond_signal(&p2_unlock); // signal für das Freigeben, wenn p2 gestoppt ist.
            pthread_cond_signal(&c_unlock); // signal für das Freigeben, wenn c gestoppt ist.
            pthread_cancel(threads[0]); // beenden
            pthread_cancel(threads[1]); // beenden
            pthread_cancel(threads[3]); // beenden
        }

    //for(i = 0; i<4; i++) {
        result[0] = pthread_join(threads[0], NULL); // &status
        result[1] = pthread_join(threads[1], NULL); // &status
        result[3] = pthread_join(threads[3], NULL); // &status
    //printf("Exit status: %d\n", *(int *)status); // Speicherzugriffsfehler
        //result[i] = *(int *)status;
    //}

	// vosichthalber vor dem Join ein Signal für den jeweiligen Thread mit condtion schicken.
    printf("Ende nach Join der Threads\n");
    //printf("Control Thread returns: %d\n",result[2]);
    printf("Producer_1 Thread returns: %d\n",result[0]);
    printf("Producer_2 Thread returns: %d\n",result[1]);
    printf("Consumer Thread returns: %d\n",result[3]);
    return 0;
}
开发者ID:CasaSky,项目名称:BSP,代码行数:53,代码来源:Aufgabe2.c

示例9: run_iddp

static int run_iddp(struct smokey_test *t, int argc, char *const argv[])
{
	struct sched_param svparam = {.sched_priority = 71 };
	struct sched_param clparam = {.sched_priority = 70 };
	pthread_attr_t svattr, clattr;
	int s;

	s = socket(AF_RTIPC, SOCK_DGRAM, IPCPROTO_IDDP);
	if (s < 0) {
		if (errno == EAFNOSUPPORT)
			return -ENOSYS;
	} else
		close(s);

	pthread_attr_init(&svattr);
	pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
	pthread_attr_setinheritsched(&svattr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&svattr, SCHED_FIFO);
	pthread_attr_setschedparam(&svattr, &svparam);

	errno = pthread_create(&svtid, &svattr, &server, NULL);
	if (errno)
		fail("pthread_create");

	pthread_attr_init(&clattr);
	pthread_attr_setdetachstate(&clattr, PTHREAD_CREATE_JOINABLE);
	pthread_attr_setinheritsched(&clattr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&clattr, SCHED_FIFO);
	pthread_attr_setschedparam(&clattr, &clparam);

	errno = pthread_create(&cltid, &clattr, &client, NULL);
	if (errno)
		fail("pthread_create");

	pthread_join(cltid, NULL);
	pthread_cancel(svtid);
	pthread_join(svtid, NULL);

	return 0;
}
开发者ID:ChunHungLiu,项目名称:xenomai,代码行数:40,代码来源:iddp.c

示例10: le_mem_ForceAlloc

//--------------------------------------------------------------------------------------------------
static ThreadObj_t* CreateThread
(
    const char*             name,       ///< [in] Name of the thread.
    le_thread_MainFunc_t    mainFunc,   ///< [in] The thread's main function.
    void*                   context     ///< [in] Value to pass to mainFunc when it is called.
)
{
    // Create a new thread object.
    ThreadObj_t* threadPtr = le_mem_ForceAlloc(ThreadPool);

    // Copy the name.  We will make the names unique by adding the thread ID later so we allow any
    // string as the name.
    LE_WARN_IF(le_utf8_Copy(threadPtr->name, name, sizeof(threadPtr->name), NULL) == LE_OVERFLOW,
               "Thread name '%s' has been truncated to '%s'.",
               name,
               threadPtr->name);

    // Initialize the pthreads attribute structure.
    LE_ASSERT(pthread_attr_init(&(threadPtr->attr)) == 0);

    // Make sure when we create the thread it takes it attributes from the attribute object,
    // as opposed to inheriting them from its parent thread.
    if (pthread_attr_setinheritsched(&(threadPtr->attr), PTHREAD_EXPLICIT_SCHED) != 0)
    {
        LE_CRIT("Could not set scheduling policy inheritance for thread '%s'.", name);
    }

    // By default, Legato threads are not joinable (they are detached).
    if (pthread_attr_setdetachstate(&(threadPtr->attr), PTHREAD_CREATE_DETACHED) != 0)
    {
        LE_CRIT("Could not set the detached state for thread '%s'.", name);
    }

    threadPtr->isJoinable = false;
    threadPtr->isStarted = false;
    threadPtr->mainFunc = mainFunc;
    threadPtr->context = context;
    threadPtr->destructorList = LE_SLS_LIST_INIT;
    threadPtr->threadHandle = 0;

    memset(&threadPtr->mutexRec, 0, sizeof(threadPtr->mutexRec));
    memset(&threadPtr->semaphoreRec, 0, sizeof(threadPtr->semaphoreRec));
    memset(&threadPtr->eventRec, 0, sizeof(threadPtr->eventRec));
    memset(&threadPtr->timerRec, 0, sizeof(threadPtr->timerRec));

    // Create a safe reference for this object.
    Lock();
    threadPtr->safeRef = le_ref_CreateRef(ThreadRefMap, threadPtr);
    Unlock();

    return threadPtr;
}
开发者ID:mbarazzouq,项目名称:legato-af,代码行数:53,代码来源:thread.c

示例11: main

int main(void)
{
	pthread_t tid;
	int ret;
	pthread_attr_t attr;
	int policy, inher;
	struct sched_param param;

	policy = SCHED_FIFO;
	param.sched_priority = 99;


	pthread_attr_init(&attr);
	
	pthread_attr_getinheritsched(&attr, &inher);
	if (inher == PTHREAD_INHERIT_SCHED)
		printf("Can't change sched policy!\n");
	else if (inher == PTHREAD_EXPLICIT_SCHED)	
		printf("Can change sched policy!\n");
#if 1
	pthread_attr_setinheritsched(&attr, 
		PTHREAD_EXPLICIT_SCHED);

	ret = pthread_attr_setschedpolicy(&attr, policy);
	if (ret) {
		printf("set policy:%s\n",
			strerror(ret));
		exit(1);
	}

	ret = pthread_attr_setschedparam(&attr, &param);
	if (ret) {
		printf("set policy:%s\n",
			strerror(ret));
		exit(1);
	}
#endif
	ret = pthread_create(&tid, &attr,
		thread_handler, NULL);
	if (ret) {
		printf("pthread_create:%s\n",
			strerror(ret));
		exit(1);	
	}
	struct timeval priv, next;
	gettimeofday(&priv, NULL);
	do_prime(300000007);
	gettimeofday(&next, NULL);

	testTime(&priv, &next);
	pthread_exit(NULL);
}
开发者ID:guolilong2012,项目名称:study,代码行数:52,代码来源:sched_attr.c

示例12: main

int main(int argc, char *argv[]) {
	struct hostent *hp;
	int flags;
	struct timeval tv;
	struct stun_state st;
        pthread_attr_t attr;
        pthread_t thread;

	gettimeofday(&tv, 0);
	srandom(tv.tv_sec + tv.tv_usec);

	hp=gethostbyname(argv[1]);
	memcpy(&stunserver.sin_addr, hp->h_addr, sizeof(stunserver.sin_addr));
	stunserver.sin_port = htons(3478);

	st.sock=socket(PF_INET,SOCK_DGRAM,0);
	flags = fcntl(st.sock, F_GETFL);
	fcntl(st.sock, F_SETFL, flags | O_NONBLOCK);

	st.bindaddr.sin_family=AF_INET;
	st.bindaddr.sin_addr.s_addr=inet_addr(argv[2]);
	st.bindaddr.sin_port=htons((random() % (65535-1023))+1023);
	bind(st.sock,(struct sockaddr *)&st.bindaddr,sizeof(struct sockaddr_in));

	pthread_attr_init(&attr);
	pthread_attr_setschedpolicy(&attr, SCHED_RR);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
	pthread_create(&thread, &attr, data_thread, &st);

	stun_send(STUN_BINDREQ,&st,NULL,0,0);

	while(1) {
		usleep(20000);
		gettimeofday(&tv,0);
		if ((tv.tv_sec*1000000+tv.tv_usec)-(st.laststun.tv_sec*1000000+st.laststun.tv_usec) > atoi(argv[3])*1000) {
			if ((st.result & STUN_NAT_SYMN) && (st.pcnt == 1)) {
				stun_send(STUN_BINDREQ,&st,NULL,0,2);
			} else {
				if (st.result < STUN_NAT_OPEN)
					printf("NEW IP:%s:%i Result: %i\n",inet_ntoa(st.bindaddr.sin_addr),ntohs(st.bindaddr.sin_port),st.result);
				else
					printf("NEW IP:%s:%i Result: %i\n",inet_ntoa(st.maddr.sin_addr),ntohs(st.maddr.sin_port),st.result);
				break;
			}
		}
	}
	pthread_attr_destroy(&attr);
	shutdown(st.sock,SHUT_RDWR);

	exit(0);
}
开发者ID:Distrotech,项目名称:stun-c,代码行数:52,代码来源:stun.c

示例13: init_priority

void init_priority(pthread_attr_t * attr, int priority)
{
    struct sched_param sched = {0};
    // 1-99, 99 is max, above 49 could starve sockets?
    // according to SOEM sample code
    sched.sched_priority = priority;
    // need EXPLICIT_SCHED or the default is
    // INHERIT_SCHED from parent process
    assert(pthread_attr_init(attr) == 0);
    assert(pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED) == 0);
    assert(pthread_attr_setschedpolicy(attr, SCHED_FIFO) == 0);
    assert(pthread_attr_setschedparam(attr, &sched) == 0);
}
开发者ID:ronaldomercado,项目名称:ethercat,代码行数:13,代码来源:rttest.c

示例14: test

int test( void )
{
  pthread_attr_t  attr;
  int             inheritsched;
  int             result;

  inheritsched = PTHREAD_INHERIT_SCHED;
  inheritsched = PTHREAD_EXPLICIT_SCHED;

  result = pthread_attr_setinheritsched( &attr, inheritsched );

  return result;
}
开发者ID:0871087123,项目名称:rtems,代码行数:13,代码来源:pthread15.c

示例15: start_syspoll_source

int start_syspoll_source( void )
{
    pthread_attr_t      pattr;
    struct sched_param  param;

    pthread_attr_init( &pattr );
    param.sched_priority = 11;
    pthread_attr_setschedparam( &pattr, &param );
    pthread_attr_setinheritsched( &pattr, PTHREAD_EXPLICIT_SCHED );
    pthread_attr_setstacksize( &pattr, 16*1024 );

    return pthread_create( NULL, NULL, syspoll_thread, NULL );
}
开发者ID:vocho,项目名称:openqnx,代码行数:13,代码来源:sources.c


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