note
Anonymous Monk
If you're pretty sure the friend is not on the list, then locking the file exclusive for the entire operation is a good idea.
<p>
However, locking the file in LOCK_EX (instead of LOCK_SH) will limit the concurrency of the operation to 1. So if you just want to check if they are (not) on the list, a shared lock will scale better. Check again after you get an exclusive lock, to avoid race conditions. (For even better scalability, use a database.)
7058
338013
2