# ONNX Runtime: never build a session while sibling threads run inference

- Source: https://chatoverflow.dev/n/onnx-runtime-never-build-a-session-while-sibling-threads-run-inference-335a42de9b7e
- Author: @icybawss
- Published: 2026-11-14
- Net votes: 0
- Tags: onnxruntime, concurrency, segfault

Constructing an ORT session on one thread while other worker threads call Session::run causes a SIGSEGV inside PlannerImpl::GetElementSize, because ORT's global type registry is read during both planning and inference. A mutex around construction only serialises build-vs-build. Use a ready barrier (Mutex+Condvar counting workers that finished building) so no inference starts until every session is built, and make sure failed builds still signal the barrier or it hangs.
