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

C++ pthread_attr_getstack函数代码示例

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

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



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


示例16: pthread_attr_init

//static
void XLinuxTask_preemptive::GetStack(void** outStackAddr, size_t* outStackSize)
{
	pthread_attr_t attr;

	pthread_attr_init(&attr);
	int res = pthread_getattr_np(pthread_self(), &attr);
	xbox_assert(res==0);

	void*   stackAddr = NULL;
	size_t  stackSize = 0;

	res = pthread_attr_getstack(&attr, &stackAddr, &stackSize);
	xbox_assert(res == 0);

	if (outStackAddr)
		*outStackAddr = stackAddr;

	if (outStackSize)
		*outStackSize = stackSize;

	pthread_attr_destroy(&attr);
}
开发者ID:StephaneH,项目名称:core-XToolbox,代码行数:23,代码来源:XLinuxTask.cpp


示例17: pthread_attr_getstack

void *AsyncFuncImpl::ThreadFunc(void *obj) {
  pthread_attr_t *attr;
  size_t stacksize, guardsize;
  void *stackaddr;

  attr = ((AsyncFuncImpl*)obj)->getThreadAttr();
  pthread_attr_getstack(attr, &stackaddr, &stacksize);

  // Get the guard page's size, because the stack address returned
  // above starts at the guard page, so the thread's stack limit is
  // stackaddr + guardsize.
  if (pthread_attr_getguardsize(attr, &guardsize) != 0)
    guardsize = 0;

  ASSERT(stackaddr != NULL);
  ASSERT(stacksize >= PTHREAD_STACK_MIN);
  Util::s_stackLimit = uintptr_t(stackaddr) + guardsize;
  Util::s_stackSize = stacksize;

  ((AsyncFuncImpl*)obj)->threadFuncImpl();
  return NULL;
}
开发者ID:AviMoto,项目名称:hiphop-php,代码行数:22,代码来源:async_func.cpp


示例18: get_self_pthread_attr

static int
get_self_pthread_attr (const char *id, void **stackaddr, size_t *stacksize)
{
  pthread_attr_t attr;
  int ret;
  pthread_t me = pthread_self ();

  if ((ret = pthread_getattr_np (me, &attr)) < 0)
    {
      printf ("%s: pthread_getattr_np failed: %s\n", id, strerror (ret));
      return 1;
    }

  if ((ret = pthread_attr_getstack (&attr, stackaddr, stacksize)) < 0)
    {
      printf ("%s: pthread_attr_getstack returned error: %s\n", id,
	      strerror (ret));
      return 1;
    }

  return 0;
}
开发者ID:AubrCool,项目名称:glibc,代码行数:22,代码来源:tst-pthread-getattr.c


示例19: pthread_self

StackLocator::StackLocator() {
    pthread_t self = pthread_self();
    pthread_attr_t selfAttrs;
    invariant(pthread_attr_init(&selfAttrs) == 0);
    invariant(pthread_getattr_np(self, &selfAttrs) == 0);
    ON_BLOCK_EXIT(pthread_attr_destroy, &selfAttrs);

    void* base = nullptr;
    size_t size = 0;

    auto result = pthread_attr_getstack(&selfAttrs, &base, &size);

    invariant(result == 0);
    invariant(base != nullptr);
    invariant(size != 0);

    // TODO: Assumes a downward growing stack. Note here that
    // getstack returns the stack *base*, being the bottom of the
    // stack, so we need to add size to it.
    _end = base;
    _begin = static_cast<char*>(_end) + size;
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:22,代码来源:stack_locator_pthread_getattr_np.cpp


示例20: pthread_self

void StackBounds::initialize()
{
    void* stackBase = 0;
    size_t stackSize = 0;

    pthread_t thread = pthread_self();
    pthread_attr_t sattr;
    pthread_attr_init(&sattr);
#if HAVE(PTHREAD_NP_H) || OS(NETBSD)
    // e.g. on FreeBSD 5.4, [email protected]
    pthread_attr_get_np(thread, &sattr);
#else
    // FIXME: this function is non-portable; other POSIX systems may have different np alternatives
    pthread_getattr_np(thread, &sattr);
#endif
    int rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize);
    (void)rc; // FIXME: Deal with error code somehow? Seems fatal.
    ASSERT(stackBase);
    pthread_attr_destroy(&sattr);
    m_bound = stackBase;
    m_origin = static_cast<char*>(stackBase) + stackSize;
}
开发者ID:AndriyKalashnykov,项目名称:webkit,代码行数:22,代码来源:StackBounds.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_attr_getstacksize函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_attr_getschedparam函数代码示例发布时间: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