在 C 中獲取並設定執行緒屬性的堆疊大小
要在 C 中獲取並設定執行緒屬性的堆疊大小,請使用以下執行緒屬性
pthread_attr_getstacksize()
用於獲取執行緒堆疊大小。stacksize 屬性給出了分配給執行緒堆疊的最小堆疊大小。如果執行成功,則返回 0,否則返回任何值。
它需要兩個引數 -
pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)
- 第一個是 pthread 屬性。
- 第二個是用於指定執行緒屬性大小。
pthread_attr_setstacksize()
用於設定新執行緒堆疊大小。stacksize 屬性給出了分配給執行緒堆疊的最小堆疊大小。如果執行成功,則返回 0,否則返回任何值。
它需要兩個引數 -
pthread_attr_setstacksize(pthread_attr_t *attr, size_t *stacksize)
- 第一個是 pthread 屬性。
- 第二個是用於指定新堆疊的大小(以位元組為單位)。
演算法
Begin Declare stack size and declare pthread attribute a. Gets the current stacksize by pthread_attr_getstacksize() and print it. Set the new stack size by pthread_attr_setstacksize() and get the stack size pthread_attr_getstacksize() and print it. End
示例程式碼
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int main() {
size_t stacksize;
pthread_attr_t a;
pthread_attr_getstacksize(&a, &stacksize);
printf("Current stack size = %d
", stacksize);
pthread_attr_setstacksize(&a, 67626);
pthread_attr_getstacksize(&a, &stacksize);
printf("New stack size= %d
", stacksize);
return 0;
}輸出
Current stack size = 50 New stack size= 67626
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP