Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

Get/Set Stack Size ของ Thread Attribute ใน C (pthread)

ใช้ pthread Attribute Functions:

pthread_attr_getstacksize()

int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)

pthread_attr_setstacksize()

int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)

ตัวอย่าง

#include <stdio.h>
#include <pthread.h>

int main() {
    size_t stacksize;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_getstacksize(&attr, &stacksize);
    printf("Current stack size = %zu\n", stacksize);
    pthread_attr_setstacksize(&attr, 67626);
    pthread_attr_getstacksize(&attr, &stacksize);
    printf("New stack size = %zu\n", stacksize);
    return 0;
}

ผลลัพธ์

Current stack size = 8388608
New stack size = 67626