Kentzo
Kentzo

Reputation: 3993

Wait until command queue done all enqueued jobs

I have an algorithm that schedules subtasks between multiple devices to solve main_task. It enqueues kernel to all command queues and attaches an event with a callback. In this callback I check whether my main_task is done and if it's not, I enqueue one more subtask. Otherwise I set shared variable is_main_task_done to true to notify other command queues that they should stop enqueueing subtasks.

Meanwhile I have to somehow prevent host's main thread from exit until is_main_task_done is set to true. Is there a cross platform solution? I've found only spinlock solution in AMD's guide so far:

while (!is_main_task_done)
 sleep(0)

But it appears to work in Windows only.

Upvotes: 0

Views: 193

Answers (1)

j13r
j13r

Reputation: 2671

It's a good idea to use semaphores here. Initialize the semaphore with the number of tasks you want to have running, and it will be ensured that only this number runs.

Upvotes: 1

Related Questions