Can I c开发者_JAVA百科all another function in a thread runner function, called by a pthread_create()
? Are there any restrictions on such functions?
Yes, you can (and doing so is fairly frequent). The main restriction is that you need to synchronize threads when two or more access the same data (at least if there's any chance that any of them might modify that data).
You can call any function from a runner function. BUT, you should make sure that any function in a multi-threaded system is protected with mutexes correctly.
You can call any function you want from a thread, but C does not automatically synchronize values. If a function uses global variables or static variables then you may get some bad surprises when you call it in multi-threaded code.
精彩评论