c++ - Ordering specification of UNIX system calls -


system calls in unix-like oses reentrant (i.e. multiple system calls may executed in parallel). there ordering constraints of system calls in sense of c/c++11 happens-before relation?

for example, let's consider following program 3 threads (in pseudo-code):

// thread 1 store x 1 store y 2  // thread 2 store y 1 store x 2  // thread 3 thread.join(1 , 2) wait((load x) == 1 && (load y) == 1) 

here, suppose x , y shared locations, , load , stores have relaxed ordering. (note: relaxed atomic accesses, races not considered bug; intentional in sense of c/c++11 semantics.) program may terminate, since (1) compiler may reorder store x 1 , store y 2, , (2) execute store y 2, store y 1, store x 2, , store x 1, (3) thread 3 may read x = 1 , y = 1 @ same time.

i know if following program may terminate. here, system calls syscall1() & syscall2() inserted in thread 1 & 2, respectively:

// thread 1 store x 1 syscall1() store y 2  // thread 2 store y 1 syscall2() store x 2  // thread 3 thread.join(1 , 2) wait((load x) == 1 && (load y) == 1) 

the program seems impossible terminate. however, in absence of ordering constraints of system calls invoked, think program may terminate. here reason. suppose syscall1() , syscall2() not serialized , may run in parallel. compiler, full knowledge of semantics of syscall1() , syscall2(), may still reorder store x 1 & syscall1() , store y 2.

so ask if there ordering constraints of system calls invoked different threads. if possible, know authoritative source kind of questions.

a system call (those listed in syscalls(2)...) elementary operation, point of view of application program in user land.

each system call (by definition) calling kernel, thru single machine code instruction (sysenter, syscall, int ...); details depend upon processor (its instruction set) , abi. kernel business (of processing system call - succeed or fail), user program sees elementary step. step (during control given kernel) last long piece of time (e.g. minutes or hours).

so program in user land runs in low level virtual machine, provided user mode machine instructions of processor augmented single "virtual" system call instruction (able of doing system call implemented kernel).

this not forbid program buggy because of race conditions.


Comments