Is the stack size of iPhone fixed?

后端 未结 2 625
闹比i
闹比i 2021-01-11 16:16

When I am trying to adjust of stack size of threads:

- (void)testStack:(NSInteger)n {
    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@s         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-11 17:02

    Actually you can set it. I am not sure if this changed with iOS 10, but on iOS 10.2.1 this does work. The only limitation is that the stack size has to be a multiple of 4kb.

    pthread_attr_t tattr;
    int ret = pthread_attr_init ( &tattr ) ;
    size_t size;
    ret = pthread_attr_getstacksize(&tattr, &size);
    printf ( "Get: ret=%d,size=%zu\n" , ret , size ) ;
    
    size = 4096 * 512 ;
    ret = pthread_attr_setstacksize(&tattr, size);
    int ret2 = pthread_attr_getstacksize(&tattr, &size);
    printf ( "Set & Get: ret=%d ret2=%d,size=%zu\n" , ret , ret2 , size ) ;
    

提交回复
热议问题