Unity.Logging in Parallel Jobs not thread-safe?

Seems like using a LoggerHandle directly on a job is not good if there’s several jobs writing to the same LoggerHandle. I get errors

“System.Exception: ThreadLoggerHandle overrides a valid LoggerHandle, this usually means you forgot to reset it or you have a race condition.”.

I need to print stuff from a Job that checks some errors and the output is basically that. All job parameters are ReadOnly.

Found this older post.

https://discussions.unity.com/t/is-it-thread-safe-to-use-the-same-loggerhandle-in-scheduled-jobs-and-their-systems/915199

“I made some multithreading tests using 4 bursted jobs/threads using the same logger handler, writing to the same file. Then a small amount of log entries did NOT find their way into the log file. So it is NOT thread-safe and the only safety is to use separate logger handles for each parallel job writing in a separate log file.”

There’s 10 jobs running in parallel. In Sequential IT WORKS.

But suddenly my game stalls to a point that I have to close Unity. Doesn’t matter if it’s executed once, it gets stuck.

1 Like

Maybe you could collect your logs in a queue or a native stream in parallel then write them sequentially at some point.