diff --git a/projects/clr/rocclr/runtime/os/os_posix.cpp b/projects/clr/rocclr/runtime/os/os_posix.cpp index 074996c264..9b7e33e317 100644 --- a/projects/clr/rocclr/runtime/os/os_posix.cpp +++ b/projects/clr/rocclr/runtime/os/os_posix.cpp @@ -390,7 +390,9 @@ void* Thread::entry(Thread* thread) { return thread->main(); } -bool Os::isThreadAlive(const Thread& thread) { return true; } +bool Os::isThreadAlive(const Thread& thread) { + return ::pthread_kill((pthread_t)thread.handle(), 0) == 0; +} const void* Os::createOsThread(amd::Thread* thread) { pthread_attr_t threadAttr; diff --git a/projects/clr/rocclr/runtime/platform/commandqueue.cpp b/projects/clr/rocclr/runtime/platform/commandqueue.cpp index 8710adc3c5..705f381267 100644 --- a/projects/clr/rocclr/runtime/platform/commandqueue.cpp +++ b/projects/clr/rocclr/runtime/platform/commandqueue.cpp @@ -31,9 +31,25 @@ HostQueue::HostQueue(Context& context, Device& device, cl_command_queue_properti bool HostQueue::terminate() { if (Os::isThreadAlive(thread_)) { + Command* marker = nullptr; + + // Send a finish if the queue is still accepting commands. + { ScopedLock sl(queueLock_); + if (thread_.acceptingCommands_) { + marker = new Marker(*this, false); + if (marker != nullptr) { + append(*marker); + queueLock_.notify(); + } + } + } + if (marker != nullptr) { + marker->awaitCompletion(); + marker->release(); + } + // Wake-up the command loop, so it can exit - { - ScopedLock sl(queueLock_); + { ScopedLock sl(queueLock_); thread_.acceptingCommands_ = false; queueLock_.notify(); }