Pass integer value through pthread_create

前端 未结 4 777
感动是毒
感动是毒 2020-11-28 14:56

I simply want to pass the value of an integer to a thread.

How can I do that?

I tried:

    int i;
    pthread_t thread_tid[10];
    for(i=0;          


        
4条回答
  •  悲哀的现实
    2020-11-28 15:32

    void *foo(void *i) {
        int a = *((int *) i);
        free(i);
    }
    
    int main {
        int *arg = (char*)malloc(sizeof(char))
        pthread_create(&thread, 0, foo, arg);
    }
    

提交回复
热议问题