diff --git a/crates/dispatch2/CHANGELOG.md b/crates/dispatch2/CHANGELOG.md index 978ad5ce4..cdfa5e6b7 100644 --- a/crates/dispatch2/CHANGELOG.md +++ b/crates/dispatch2/CHANGELOG.md @@ -59,6 +59,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - **BREAKING**: Use `extern "C-unwind"` instead of `extern "C"` in certain functions that required that. - **BREAKING**: Use `isize` instead of `usize` in certain functions where that is more correct. +- **BREAKING**: An `F: 'static` bound was added to the following methods to make + sure any referenced values passed to them are borrowed for long + enough since they perform their `work` asynchronously (#689): + - `Group::exec_async` + - `Queue::exec_async` + - `Queue::barrier_async` + - `Queue::barrier_async_and_wait` ## 0.1.0 - 2022-10-02 diff --git a/crates/dispatch2/src/group.rs b/crates/dispatch2/src/group.rs index 454118c90..dbcfbc438 100644 --- a/crates/dispatch2/src/group.rs +++ b/crates/dispatch2/src/group.rs @@ -38,7 +38,9 @@ impl Group { /// Submit a function to a [Queue] and associates it with the [Group]. pub fn exec_async(&self, queue: &Queue, work: F) where - F: Send + FnOnce(), + // We need `'static` to make sure any referenced values are borrowed for + // long enough since `work` will be performed asynchronously. + F: Send + FnOnce() + 'static, { let work_boxed = Box::into_raw(Box::new(work)).cast::(); diff --git a/crates/dispatch2/src/queue.rs b/crates/dispatch2/src/queue.rs index 6c62a9151..38940477a 100644 --- a/crates/dispatch2/src/queue.rs +++ b/crates/dispatch2/src/queue.rs @@ -226,7 +226,9 @@ impl Queue { /// Submit a function for asynchronous execution on the [Queue]. pub fn exec_async(&self, work: F) where - F: Send + FnOnce(), + // We need `'static` to make sure any referenced values are borrowed for + // long enough since `work` will be performed asynchronously. + F: Send + FnOnce() + 'static, { let work_boxed = Box::into_raw(Box::new(work)).cast(); @@ -254,7 +256,9 @@ impl Queue { /// Enqueue a barrier function for asynchronous execution on the [Queue] and return immediately. pub fn barrier_async(&self, work: F) where - F: Send + FnOnce(), + // We need `'static` to make sure any referenced values are borrowed for + // long enough since `work` will be performed asynchronously. + F: Send + FnOnce() + 'static, { let work_boxed = Box::into_raw(Box::new(work)).cast(); @@ -276,7 +280,9 @@ impl Queue { /// Submit a function for synchronous execution and mark the function as a barrier for subsequent concurrent tasks. pub fn barrier_async_and_wait(&self, work: F) where - F: Send + FnOnce(), + // We need `'static` to make sure any referenced values are borrowed for + // long enough since `work` will be performed asynchronously. + F: Send + FnOnce() + 'static, { let work_boxed = Box::into_raw(Box::new(work)).cast();