Beginner Posix/pthread Question

Pages: 12
Only if commonfunc() is not reentrant (it depends on global or static state, or performs certain types of I/O).
For example, this function should be locked:
1
2
3
4
void f(){
    static int i=0;
    return i++;
}

Some I/O is safe. For example, writing concurrently to different files is generally safe (if the OS supports threading, it almost certainly has a thread-safe file system); doing it to the same file is not, specially when appending content to the end, and doubly specially if you're writing to a single file object and jumping around in the file.
Topic archived. No new replies allowed.
Pages: 12