-
-
Notifications
You must be signed in to change notification settings - Fork 207
Description
This issue was created in the GarageGames Repository (Link to original issue).
The issue was originally created by @jamesu and had a total of 3 comments that may contain additional information. The original issue description is pasted below:
I bumped into an issue with the console logger in a project. If we have the following situation:
Thread 1: Con::printf("One");
Thread 2: Con::printf("Two");
Thread 3: Con::printf("Three");
Usually you'd expect the following to be sent through to the consumers, in whatever order the threads manage to call the consumer:
One
Two
Three
Depending on the timing of these threads you may get the following sent to the consumers:
One
Three
In console.cpp we have:
static void _printf(ConsoleLogEntry::Level level, ConsoleLogEntry::Type type, const char* fmt, va_list argptr)
{
if (!active)
return;
Con::active = false;
Essentially the "active" check is just a check to prevent a recursion later on in the code. What is happening is since there is no synchronization in _printf, Thread 1 may set active to true causing Thread 2 to ignore the print, while Thread 3 may find active is false again as Thread 1 has finished printing the entry.
If you have the log buffer enabled or the console, you'll likely get a crash as yet again there is no synchronization whatsoever when pushing the log entry to the console log.
In my case since I don't use any of the console stuff (just the consumer list) I solved the issue by just having a lock on the consumer, but I figured maybe a better solution is needed for Torque3D...