JohnathonNow / Bending

A 2D, multiplayer online action game.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The OrderedOutputStream is probably not actually thread-safe

JohnathonNow opened this issue · comments

while (access) {
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
access = true;
stack.add(new Message(BB, ID));
access = false;

This kind of locking mechanism does not prevent two threads from accessing the critical section. It should probably just be a synchronized method.

@JohnathonNow Can I also propose that this check is moved to the start of this method?

If the active flag is set to false, you will have a memory leak as you continue to add to the stack despite the run thread no longer consuming things off the stack.

Thanks for the contribution, and I agree with your proposal.