This solution appears to work. However, it does not follow all best practices. For example, the use of friend declarations, and the need to make the lock/unlock functions in File public (in order to get friend status). However, it passes the stress test without errors.