From 7bd0884327cc0cefff78bd7e3d68b12e67a72e21 Mon Sep 17 00:00:00 2001 From: SerVB Date: Thu, 6 Feb 2020 22:15:57 +0300 Subject: [PATCH] Fix data race --- src/Main.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Main.kt b/src/Main.kt index 718ddee..fbdecaa 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -8,7 +8,9 @@ class ChatServer(port: Int) : WebSocketServer(InetSocketAddress(port)) { private var nextId = 0 override fun onOpen(connection: WebSocket, handshake: ClientHandshake?) { - val id = ++nextId + val id = synchronized(this) { + ++nextId + } val message = "#$id connected" sendToAll(message)