Can I call another function in a thread runner function, called by a pthread_create()
? Are there any restrictions on such functions?
views:
46answers:
3
+5
A:
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).
Jerry Coffin
2010-09-30 19:54:57
+1
A:
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.
Starkey
2010-09-30 19:55:40
+1
A:
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.
Michael Shopsin
2010-09-30 20:44:44