In an interview, I was being asked to implement a simple Queue and protect for multi-threading. My implementation had a class variable that contained the currentSize and I only protected the push and pop functions but not the isFull and isEmpty functions.
Interviewer asked me why I didn't protect the isFull and isEmpty functions. I said that it is unnecessary for two reasons,
- It is not changing the currentSize
- Regardless of whether the isFull and isEmpty functions yields correct returns, you can never have any meaningful use of it as in a multithreaded environment, it will change instantaneously.
The interviewer didn't agree but I didn't push it further and cleared the interview.
Is my reasoning valid?