Skip to content

Commit 3eb5331

Browse files
authored
Merge pull request #1131 from openmultiplayer/amir/fix-stdin-lock
fix sdtin lock from getline when shutting down
2 parents faf5db1 + 3a4cf34 commit 3eb5331

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Server/Components/Console/console_impl.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ConsoleComponent final : public IConsoleComponent, public CoreEventHandler
6565
String cmd;
6666
ThreadProcData* threadData;
6767
std::thread cinThread;
68+
std::thread::native_handle_type nativeThreadHandle;
6869

6970
struct PlayerRconCommandHandler : public SingleNetworkInEventHandler
7071
{
@@ -212,7 +213,11 @@ class ConsoleComponent final : public IConsoleComponent, public CoreEventHandler
212213

213214
threadData = new ThreadProcData { true, this };
214215
cinThread = std::thread(ThreadProc, threadData);
216+
nativeThreadHandle = cinThread.native_handle();
217+
218+
#ifndef WIN32
215219
cinThread.detach();
220+
#endif
216221
}
217222

218223
void onReady() override
@@ -257,10 +262,16 @@ class ConsoleComponent final : public IConsoleComponent, public CoreEventHandler
257262
if (threadData)
258263
{
259264
threadData->valid = false;
265+
266+
#ifdef WIN32
260267
if (cinThread.joinable())
261268
{
262269
cinThread.join();
263270
}
271+
#else
272+
pthread_cancel(nativeThreadHandle);
273+
#endif
274+
264275
delete threadData;
265276
threadData = nullptr;
266277
}

0 commit comments

Comments
 (0)