Skip to content

Commit

Permalink
Free if broadcast fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Sep 27, 2024
1 parent 93f290d commit 7ff645c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/std/threads/fixed_pool.c3
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ macro void! FixedThreadPool.@shutdown(&self, #stop) @private
*/
fn void! FixedThreadPool.push(&self, ThreadPoolFn func, args...)
{
self.mu.lock()!;
mu.in_lock()!;
defer self.mu.unlock()!!;
if (self.qindex == self.queue.len) return ThreadPoolResult.QUEUE_FULL?;
any[] data;
Expand All @@ -120,6 +120,10 @@ fn void! FixedThreadPool.push(&self, ThreadPoolFn func, args...)
}
self.queue[self.qindex] = { .func = func, .args = data };
self.qindex++;
defer catch
{
free_qitem(self.queue[--self.qindex]);
}
// Notify the threads that work is available.
self.notify.broadcast()!;
}
Expand Down

0 comments on commit 7ff645c

Please sign in to comment.