How to spawn n threads?

前端 未结 3 935
温柔的废话
温柔的废话 2021-01-12 04:12

I\'m trying to write a multi-threaded program, the number of threads based on command-line input, and so I can\'t hard-code pre-declared threads. Is this a valid way of doin

3条回答
  •  太阳男子
    2021-01-12 05:03

    The first for loop is not valid C, and I'm not sure what you want it to do. Just remove it and the rest of the code looks ok, aside from the incorrect cast on foobar_function. The cast should be:

    (void *(*)(void *))foobar_function
    

    but unless the type is already this, or something very close, your program probably has undefined behavior. It would be better to fix the function signature so no cast is needed.

提交回复
热议问题