Pthread распределений в target-c - PullRequest
       16

Pthread распределений в target-c

0 голосов
/ 19 февраля 2019

Структура pthread, выделенная в target-c, показывает их как постоянное распределение в стеке и никогда не освобождается. Что-то не так с тем, как я использую структуру pthread_t, или мне нужно каким-то образом явно удалить их?

Структура pthread_t, используемая в pthread_create, никогда не освобождается автоматически.Вот простой код.

- (void)spawnPThread:(int) counter {
    pthread_t thread;
    pthread_create(&thread, NULL, startThread,(void *) &counter);
    pthread_join(thread, NULL);
}

void *startThread(void *data) {
    NSLog(@"%@", [NSThread currentThread]);
    int* counter = (int *) data;
    int i = *counter;
    while(i>0){
        NSLog(@"%d",i--);
    }
    return NULL;
}

порождая нить каждый раз, когда я нажимаю кнопку

- (IBAction)buttonWasPressed:(id)sender {
    NSLog(@"Button pressed");
    static int counter = 1;
    [self spawnPThread:counter];
}

Allocations shown in Instruments

...