tags:

views:

46

answers:

3

Can I call another function in a thread runner function, called by a pthread_create()? Are there any restrictions on such functions?

+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
+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
+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