C read and thread safety (linux) -


what happen if call read (or write, or both) in 2 different thread, on same file descriptor (lets says interested local file, , it's socket file descriptor), without using explicitly synchronization mechanism?

read , write syscall, so, on single core cpu, it's unlucky 2 read executed "at same time". multiple cores...

what linux kernel do?

and let's bit more general : behavior same other kernels (like bsds) ?

edit : according close documentation, should sure file descriptor isn't used syscall in other thread. seams explicit synchronization required before closing file descriptor (and so, around read/write if thread may call still running).

any system level (syscall) file descriptor access thread safe in mainstream unix-like oses. though depending on age not signal safe.

if call read, write, accept or similar on file descriptor 2 different tasks kernel's internal locking mechanism resolve contention.

for reads each byte may read once though , writes go in undefined order.

the stdio library functions fread, fwrite , co. have default internal locking on control structures, though using flags possible disable that.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -