【问题标题】:When using Windows threads, can I specify a buffer to use for a thread's stack, similar to pthread_attr_setstack()?使用 Windows 线程时,是否可以指定一个缓冲区用于线程的堆栈,类似于 pthread_attr_setstack()?
【发布时间】:2012-06-12 07:30:43
【问题描述】:

pthreads 允许用户提供一块内存用于线程堆栈:

size_t stack_size = 1024*1024*4;
void *stack = malloc( stack_size );
pthread_attr_t attributes;
pthread_attr_init( &attributes );
pthread_attr_setstack( &attributes, stack, stack_size );
pthread_t thread_id;
pthread_create( &thread_id, &attributes, worker_function, NULL 

Windows 线程是否提供类似的功能? CreateThread 的第二个参数允许指定堆栈的最小大小,但我看不到指定要使用的缓冲区地址的方法。

【问题讨论】:

  • 除非我弄错了,否则答案是“不”。

标签: windows multithreading winapi pthreads


【解决方案1】:

您不能像 Jerry Coffin 在评论中提到的那样为堆栈指定内存,您只能指定堆栈的大小作为CreateThread 调用的第二个参数。

更多信息here

【讨论】:

    猜你喜欢
    • 2021-02-04
    • 2017-02-16
    • 1970-01-01
    • 2015-09-02
    • 2015-12-31
    • 2011-03-14
    • 1970-01-01
    • 2018-09-22
    • 2011-07-28
    相关资源
    最近更新 更多