diff --git a/mlx/scheduler.h b/mlx/scheduler.h index 40e33f2be..d14dd4fd5 100644 --- a/mlx/scheduler.h +++ b/mlx/scheduler.h @@ -24,7 +24,9 @@ struct StreamThread { std::thread thread; StreamThread(Stream stream) - : stop(false), stream(stream), thread(&StreamThread::thread_fn, this) {} + : stop(false), stream(stream), thread(&StreamThread::thread_fn, this) { + metal::new_stream(stream); + } ~StreamThread() { synchronize(stream); @@ -37,7 +39,6 @@ struct StreamThread { } void thread_fn() { - bool initialized = false; while (true) { std::function task; { @@ -50,15 +51,6 @@ struct StreamThread { q.pop(); } - // thread_fn may be called from a static initializer and we cannot - // call metal-cpp until all static initializers have completed. waiting - // for a task to arrive means that user code is running so metal-cpp - // can safely be called. - if (!initialized) { - initialized = true; - metal::new_stream(stream); - } - task(); } }