T
Time Waster
Is this a stupid use of flock:
FILE *fp=fopen(SOME_FILE_CONSTANT,"r+");
flock(fileno(fp),LOCK_EX);
something important here, including reads and a write to fp
flock(fileno(fp),LOCK_UN);
fclose(fp);
Does this accomplish real locking, or just narrow down the
race quite a bit? (Race existing between the unlock and the
fclose(), i guess.)
Normally I would think you'd want a separate file to do
nothing but the locking, and guard the use of the real data
file with locks on the lockfile.
Also, assuming the above is stupid, is the following a wee
bit smarter:
FILE *fp=fopen(SOME_FILE_CONSTANT,"r+");
flock(fileno(fp),LOCK_EX);
something important here, including reads and a write to fp
fflush(fp); <<---- at least try to make
fdatasync(fp); <<---- sure contents out before unlock
flock(fileno(fp),LOCK_UN);
fclose(fp);
(Or does this add very little?)
TIA!
FILE *fp=fopen(SOME_FILE_CONSTANT,"r+");
flock(fileno(fp),LOCK_EX);
something important here, including reads and a write to fp
flock(fileno(fp),LOCK_UN);
fclose(fp);
Does this accomplish real locking, or just narrow down the
race quite a bit? (Race existing between the unlock and the
fclose(), i guess.)
Normally I would think you'd want a separate file to do
nothing but the locking, and guard the use of the real data
file with locks on the lockfile.
Also, assuming the above is stupid, is the following a wee
bit smarter:
FILE *fp=fopen(SOME_FILE_CONSTANT,"r+");
flock(fileno(fp),LOCK_EX);
something important here, including reads and a write to fp
fflush(fp); <<---- at least try to make
fdatasync(fp); <<---- sure contents out before unlock
flock(fileno(fp),LOCK_UN);
fclose(fp);
(Or does this add very little?)
TIA!