c - File locking between threads and processes -



c - File locking between threads and processes -

i have programme spawns multiple processes or threads, each of writes line on file, don't want line mixed up, need exclusive access file.

more specifically, in first case, have process f spawns several kid processes (c1, c2, c3, c4, ...), , want block access f, c2, c3, c4, ... when c1 writing.

in sec case, have same process f spawns several threads (t1, t2, t3, t4, ...) and, again, want block access f, t2, t3, t4, ... when t1 writing.

i'm guessing function flock() takes care of first part, threads case? , windows platform?

you can utilize locking mechanism want. between threads, mutex simplest. access file protected mutex, no 2 threads seek write file @ same time.

for processes, can utilize process-shared mutex. on windows, can utilize named mutex.

c windows multithreading unix locking

Comments

Popular posts from this blog

php - How to pass multiple values from url -

php - Laravel not returning controller -

c# - Confused on how to specify a Platform and Version while using ChromeOptions for RemoteWebDriver with Selenium donNet since recent updates -