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


C++ pthread_attr_getstack函数代码示例

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


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

示例1: main

int main(void)
{
	pthread_attr_t attr;
	int rc;

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

	/* Get the default stack_addr and stack_size value */
	rc = pthread_attr_getstack(&attr, &stack_addr, &stack_size);
	if (rc != 0) {
		perror(ERROR_PREFIX "pthread_attr_getstack");
		exit(PTS_UNRESOLVED);
	}
	/* printf("stack_addr = %p, stack_size = %u\n", stack_addr, stack_size); */

	stack_size = PTHREAD_STACK_MIN;

	if (posix_memalign(&stack_addr, sysconf(_SC_PAGE_SIZE),
			   stack_size) != 0) {
		perror(ERROR_PREFIX "out of memory while "
		       "allocating the stack memory");
		exit(PTS_UNRESOLVED);
	}

	stack_addr = stack_addr + OFFSET;
	/* printf("stack_addr = %p, stack_size = %u\n", stack_addr, stack_size); */
	rc = pthread_attr_setstack(&attr, stack_addr, stack_size);
	if (rc != EINVAL) {
		printf("The function didn't fail when stackaddr "
		       "lacks proper alignment\n");
	}

	stack_addr = stack_addr + OFFSET;
	stack_size = PTHREAD_STACK_MIN + OFFSET;
	/* printf("stack_addr = %p, stack_size = %u\n", stack_addr, stack_size); */
	rc = pthread_attr_setstack(&attr, stack_addr, stack_size);
	if (rc != EINVAL) {
		printf("The function didn't fail when (stackaddr + stacksize) "
		       "lacks proper alignment\n");
	}

	rc = pthread_attr_destroy(&attr);
	if (rc != 0) {
		perror(ERROR_PREFIX "pthread_attr_destroy");
		exit(PTS_UNRESOLVED);
	}

	printf("Test PASSED\n");
	return PTS_PASS;
}
开发者ID:1587,项目名称:ltp,代码行数:55,代码来源:7-1.c

示例2: pthread_attr_init

void *nativeStackBase() {
    pthread_attr_t attr;
    size_t size;
    void *addr;

    pthread_attr_init(&attr);
    pthread_attr_get_np(pthread_self(), &attr);
    pthread_attr_getstack(&attr, &addr, &size);

    return addr+size;
}
开发者ID:cfriedt,项目名称:jamvm,代码行数:11,代码来源:os.c

示例3: mono_threads_core_get_stack_bounds

void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
	pthread_attr_t attr;

	*staddr = NULL;
	*stsize = (size_t)-1;

	pthread_getattr_np (pthread_self (), &attr);
	pthread_attr_getstack (&attr, (void**)staddr, stsize);
	pthread_attr_destroy (&attr);
}
开发者ID:Adamcbrz,项目名称:mono,代码行数:12,代码来源:mono-threads-linux.c

示例4: pthread_attr_getstack_18908062_helper

static void pthread_attr_getstack_18908062_helper(void*) {
  char local_variable;
  pthread_attr_t attributes;
  pthread_getattr_np(pthread_self(), &attributes);
  void* stack_base;
  size_t stack_size;
  pthread_attr_getstack(&attributes, &stack_base, &stack_size);

  // Test whether &local_variable is in [stack_base, stack_base + stack_size).
  ASSERT_LE(reinterpret_cast<char*>(stack_base), &local_variable);
  ASSERT_LT(&local_variable, reinterpret_cast<char*>(stack_base) + stack_size);
}
开发者ID:loongchow,项目名称:platform_bionic,代码行数:12,代码来源:pthread_test.cpp

示例5: taskGetInfo

STATUS taskGetInfo(TASK_ID task_id, TASK_DESC *desc)
{
	int vfirst, vlast, ret;
	struct wind_task *task;
	struct WIND_TCB *tcb;
	pthread_attr_t attr;
	size_t stacksize;
	void *stackbase;

	task = get_wind_task(task_id);
	if (task == NULL) {
		errno = S_objLib_OBJ_ID_ERROR;
		return ERROR;
	}

	tcb = task->tcb;
	desc->td_tid = task_id;
	desc->td_priority = wind_task_get_priority(task);
	desc->td_status = get_task_status(task);
	desc->td_flags = tcb->flags;
	strncpy(desc->td_name, task->name, sizeof(desc->td_name));
	desc->td_entry = tcb->entry;
	desc->td_errorStatus = *task->thobj.errno_pointer;
	ret = pthread_getattr_np(task->thobj.tid, &attr);
	put_wind_task(task);

	/*
	 * If the target does not support pthread_getattr_np(), we are
	 * out of luck for determining the stack information. We just
	 * zero it.
	 */
	if (ret) {
		/* No idea, buddy. */
		desc->td_stacksize = 0;
		desc->td_pStackBase = NULL;
	} else {
		pthread_attr_getstack(&attr, &stackbase, &stacksize);
		desc->td_stacksize = stacksize;
		desc->td_pStackBase = stackbase;

		if (&vfirst < &vlast)
			/* Stack grows upward. */
			desc->td_pStackEnd = (caddr_t)stackbase + stacksize;
		else
			/* Stack grows downward. */
			desc->td_pStackEnd = (caddr_t)stackbase - stacksize;
	}

	return OK;
}
开发者ID:Lmaths,项目名称:xenomai-forge,代码行数:50,代码来源:taskInfo.c

示例6: defined

void *nativeStackBase() {
#if defined(__UCLIBC__) || defined(__EMSCRIPTEN__)
    return NULL;
#else
    pthread_attr_t attr;
    void *addr;
    size_t size;

    pthread_getattr_np(pthread_self(), &attr);
    pthread_attr_getstack(&attr, &addr, &size);

    return addr+size;
#endif
}
开发者ID:vilie,项目名称:javify,代码行数:14,代码来源:os.c

示例7: otherThreadStackPointer

static inline void* otherThreadStackPointer(const PlatformThreadRegisters& regs)
{
#if OS(DARWIN)

#if __DARWIN_UNIX03

#if CPU(X86)
    return reinterpret_cast<void*>(regs.__esp);
#elif CPU(X86_64)
    return reinterpret_cast<void*>(regs.__rsp);
#elif CPU(PPC) || CPU(PPC64)
    return reinterpret_cast<void*>(regs.__r1);
#elif CPU(ARM)
    return reinterpret_cast<void*>(regs.__sp);
#else
#error Unknown Architecture
#endif

#else // !__DARWIN_UNIX03

#if CPU(X86)
    return reinterpret_cast<void*>(regs.esp);
#elif CPU(X86_64)
    return reinterpret_cast<void*>(regs.rsp);
#elif CPU(PPC) || CPU(PPC64)
    return reinterpret_cast<void*>(regs.r1);
#else
#error Unknown Architecture
#endif

#endif // __DARWIN_UNIX03

// end OS(DARWIN)
#elif CPU(X86) && OS(WINDOWS)
    return reinterpret_cast<void*>((uintptr_t) regs.Esp);
#elif CPU(X86_64) && OS(WINDOWS)
    return reinterpret_cast<void*>((uintptr_t) regs.Rsp);
#elif USE(PTHREADS)
    void* stackBase = 0;
    size_t stackSize = 0;
    int rc = pthread_attr_getstack(&regs, &stackBase, &stackSize);
    (void)rc; // FIXME: Deal with error code somehow? Seems fatal.
    ASSERT(stackBase);
    return static_cast<char*>(stackBase) + stackSize;
#else
#error Need a way to get the stack pointer for another thread on this platform
#endif
}
开发者ID:BGmot,项目名称:Qt,代码行数:48,代码来源:MachineStackMarker.cpp

示例8: mono_threads_core_get_stack_bounds

void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
	pthread_attr_t attr;
	guint8 *current = (guint8*)&attr;

	*staddr = NULL;
	*stsize = (size_t)-1;

	pthread_getattr_np (pthread_self (), &attr);
	pthread_attr_getstack (&attr, (void**)staddr, stsize);
	pthread_attr_destroy (&attr);

	if (*staddr && ((current <= *staddr) || (current > *staddr + *stsize)))
		slow_get_thread_bounds (current, staddr, stsize);
}
开发者ID:0ostreamo0,项目名称:mono,代码行数:16,代码来源:mono-threads-android.c

示例9: main

int main()
{
	pthread_attr_t attr;
	int rc;

	/* Initialize attr */
	rc = pthread_attr_init(&attr);
	if( rc != 0) {
		perror(ERROR_PREFIX "pthread_attr_init");
		exit(PTS_UNRESOLVED);
	}
	
	/* Get the default stack_addr and stack_size value */	
	rc = pthread_attr_getstack(&attr, &stack_addr, &stack_size); 	
	if( rc != 0) {
		perror(ERROR_PREFIX "pthread_attr_getstack");
		exit(PTS_UNRESOLVED);
	}
	/* printf("stack_addr = %p, stack_size = %u\n", stack_addr, stack_size); */

	stack_size = STACKSIZE;

	if (posix_memalign (&stack_addr, sysconf(_SC_PAGE_SIZE), 
            stack_size) != 0)
    	{
      		perror (ERROR_PREFIX "out of memory while "
                        "allocating the stack memory");
      		exit(PTS_UNRESOLVED);
    	}

	/* printf("stack_addr = %p, stack_size = %u\n", stack_addr, stack_size); */
	rc = pthread_attr_setstack(&attr, stack_addr, stack_size);
        if (rc != EINVAL ) {
                perror(ERROR_PREFIX "Got the wrong return value");
                exit(PTS_FAIL);
        }

	rc = pthread_attr_destroy(&attr);
	if(rc != 0)
        {
                perror(ERROR_PREFIX "pthread_attr_destroy");
		exit(PTS_UNRESOLVED);
        }
	
	printf("Test PASSED\n");
	return PTS_PASS;
}
开发者ID:chathhorn,项目名称:posixtestsuite,代码行数:47,代码来源:6-1.c

示例10: get_stack_attr

static int get_stack_attr(void *low, void *high)
{
  /* GNU Pthread specific */
  pthread_attr_t attr;
  uintptr_t stackaddr;
  size_t stacksize;
  if (pthread_getattr_np(pthread_self(), &attr)) {
    return 1;
  }
  if (pthread_attr_getstack(&attr, (void *)&stackaddr, &stacksize)) {
    return 1;
  }
  *(uintptr_t *)low = stackaddr;
  *(uintptr_t *)high = stackaddr + stacksize;

  return 0;
}
开发者ID:HPDCS,项目名称:stmEnergyOptimization,代码行数:17,代码来源:abi.c

示例11: mas_ticker_start

/* naming : pthread_create = start */
int
mas_ticker_start( const mas_options_t * popts )
{
  CTRL_PREPARE;
  /* EVAL_PREPARE; */
  int r = 0;

  MFP( "\x1b]2;starting ticker; mode:%d\x7", ctrl.ticker_mode );
  if ( !ctrl.threads.n.ticker.thread )
  {
    {
      ( void ) /* r = */ pthread_attr_getstack( &ctrl.thglob.ticker_attr, &ticker_stackaddr, &ticker_stacksize );
      tMSG( "creating ticker thread stack:%lu @ %p", ( unsigned long ) ticker_stacksize, ticker_stackaddr );
      HMSG( "+ TICKER mode %d", ctrl.ticker_mode );
    }

    /* if ( !tmp )                 */
    /*   tmp = mas_malloc( 4321 ); */
    MAS_LOG( "starting ticker th." );

    /* r = mas_xpthread_create( &ctrl.threads.n.ticker.thread, mas_ticker_th, MAS_THREAD_TICKER, NULL ); */
    r = pthread_create( &ctrl.threads.n.ticker.thread, &ctrl.thglob.ticker_attr, mas_ticker_th, NULL );
#ifdef SCHED_IDLE
    {
      int policy, rs;
      struct sched_param sched;

      rs = pthread_getschedparam( ctrl.threads.n.ticker.thread, &policy, &sched );
      /* SCHED_IDLE ... SCHED_RR */
      rs = pthread_setschedparam( ctrl.threads.n.ticker.thread, SCHED_IDLE, &sched );
      /* rs = pthread_getschedparam( ctrl.threads.n.ticker.thread, &policy, &sched ); */
      MAS_LOG( "(%d) created(?) ticker thread [%lx] %d - %d (%d)", r, ctrl.threads.n.ticker.thread, policy, sched.sched_priority, rs );
      tMSG( "(%d) created(?) ticker thread [%lx] %d - %d (%d)", r, ctrl.threads.n.ticker.thread, policy, sched.sched_priority, rs );
    }
#else
    MAS_LOG( "(%d) created(?) ticker thread [%lx]", r, ctrl.threads.n.ticker.thread );
#endif
  }
  else
  {
    MAS_LOG( "running w/o ticker th." );
  }
  return r;
}
开发者ID:mastarink,项目名称:github-zocromas,代码行数:45,代码来源:mas_ticker.c

示例12: main

int main(void)
{
	pthread_t tid;
	pthread_attr_t attr;
	void *stack_addr;
	int stack_size;
	int ret;

	while (1)
	{
		stack_addr = malloc(PAGE_SIZE * 8);	
		// 1. 指针不能位运算,因此转换成unsigned long
		// 2. & 0x7 检查地址是否对齐: 32位系统,2^12 >> 0x1000
		if ((unsigned long)stack_addr & 0x7 != 0)
		{
			printf("地址不是对齐的\n");
			free(stack_addr);
		}
		else
			break;
	}

	printf("stack_addr: %p\n", stack_addr);

	pthread_attr_init(&attr);
	pthread_attr_setstack(&attr, stack_addr, PAGE_SIZE * 8);
	pthread_attr_getstack(&attr, &stack_addr, &stack_size);
	printf("stack_addr: %p, stack_size: %#x\n", stack_addr, stack_size);

	pthread_create(&tid, &attr, thr_rtn, NULL);

	ret = pthread_join(tid, NULL);
	if (ret != 0)
	{
		printf("thread has detached\n");
		perror("pthread_join");
	}
	
	free(stack_addr);
	pthread_attr_destroy(&attr);

	return 0;
}
开发者ID:royye62,项目名称:mydemo,代码行数:43,代码来源:7pthread_attr.c

示例13: pthread_attr_getstack

void Thread::_poison_stack()
{
    pthread_attr_t attr;
    size_t stack_size, guard_size;
    void *stackp;
    uint8_t *end, *start, *curr;
    uint32_t *p;

    if (pthread_getattr_np(_ctx, &attr) != 0 ||
        pthread_attr_getstack(&attr, &stackp, &stack_size) != 0 ||
        pthread_attr_getguardsize(&attr, &guard_size) != 0) {
        return;
    }

    /* The stack either grows upward or downard. The guard part always
     * protects the end */
    end = (uint8_t *) stackp;
    start = end + stack_size;
    curr = (uint8_t *) alloca(sizeof(uint32_t));

    /* if curr is closer to @end, the stack actually grows from low to high
     * virtual address: this is because this function should be executing very
     * early in the thread's life and close to the thread creation, assuming
     * the actual stack size is greater than the guard size and the stack
     * until now is resonably small */
    if (abs(curr - start) > abs(curr - end)) {
        std::swap(end, start);
        end -= guard_size;

        for (p = (uint32_t *) end; p > (uint32_t *) curr; p--) {
            *p = STACK_POISON;
        }
    } else {
        end += guard_size;

        for (p = (uint32_t *) end; p < (uint32_t *) curr; p++) {
            *p = STACK_POISON;
        }
    }

    _stack_debug.start = (uint32_t *) start;
    _stack_debug.end = (uint32_t *) end;
}
开发者ID:Annashuang,项目名称:ardupilot,代码行数:43,代码来源:Thread.cpp

示例14: tf

static void *
tf (void *a)
{
  int result = 0;

  puts ("child start");

  pthread_attr_t attr;
  if (pthread_getattr_np (pthread_self (), &attr) != 0)
    {
      puts ("getattr_np failed");
      exit (1);
    }

  size_t test_size;
  void *test_stack;
  if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
    {
      puts ("attr_getstack failed");
      exit (1);
    }

  if (test_size != size)
    {
      printf ("child: reported size differs: is %zu, expected %zu\n",
	      test_size, size);
      result = 1;
    }

  if (test_stack != stack)
    {
      printf ("child: reported stack address differs: is %p, expected %p\n",
	      test_stack, stack);
      result = 1;
    }

  puts ("child OK");

  return result ? (void *) 1l : NULL;
}
开发者ID:Xilinx,项目名称:eglibc,代码行数:40,代码来源:tst-stack1.c

示例15: display_stack_related_attributes

static void
display_stack_related_attributes(pthread_attr_t *attr, char *prefix)
{
    int s;
    size_t stack_size, guard_size;
    void *stack_addr;

    s = pthread_attr_getguardsize(attr, &guard_size);
    if (s != 0)
        handle_error_en(s, "pthread_attr_getguardsize");
    printf("%sGuard size 	 = %lu bytes\n", prefix, guard_size);

    s = pthread_attr_getstack(attr, &stack_addr, &stack_size);
    if (s != 0)
        handle_error_en(s, "pthread_attr_getstack");
    printf("%sStack address	 = %p", prefix, stack_addr);
    if (stack_size > 0)
        printf(" (EOS = %p)", (char *) stack_addr + stack_size);
    printf("\n");
    printf("%sStack size 	 = 0x%lx (%lu) bytes\n",
           prefix, stack_size, stack_size);
}
开发者ID:lilijreey,项目名称:Linux-learning,代码行数:22,代码来源:getstackinfo.c


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