and thread 3 is maybe reading a record, and thread 4 does a findByCriteria. all crud-methods are changing the file pointer, so you have to make sure moving the file pointer and reading or writing a record is executed as one atomic operation.
This has nothing to do with lock/unlock a record.
So you need protection:
- at file-level: make sure your file-pointer isn't moved before you actually can read/write, because that will corrupt your db-file
- at record-level: a record can only be deteleted / updated if it's locked
you have to implement both protections because each one is focussing on a different issue
i don't know if it deadlocks, but what i know is when you don't do both, you could end up with a messed up db-file (if you work with 1 single RAF and multiple data-instances) and rooms begin booked by several different customers