I don't think this is thread safe, unfortunately; there can be multiple clients simultaneously logging in (in fact, in most workloads, this will /normally/ be the case, since they all log in as the first step), they're all going to try to grab userList[0] (at the same time), and they're all going to try to +=1 at the same time. Not only that but you do a +1 and *then* set the count back to 0 if it got too high. But if another concurrent login happened after the +1 but before the reset to 0, you're going to get a array out of bounds panic.