@@ -195,7 +195,6 @@ pub mod custom_callable {
195
195
}
196
196
197
197
// Without this feature, any access to the global binding from another thread fails; so the from_local_fn() cannot be tested in isolation.
198
- // #[cfg(feature = "experimental-threads")]
199
198
#[ itest]
200
199
fn callable_from_local_fn_crossthread ( ) {
201
200
// This static is a workaround for not being able to propagate failed `Callable` invocations as panics.
@@ -212,17 +211,31 @@ pub mod custom_callable {
212
211
let crosser = ThreadCrosser :: new ( callable) ;
213
212
214
213
// Create separate thread and ensure calling fails.
215
- // expect_panic(
216
- // "Callable created with from_local_fn() must panic when invoked on other thread",
217
- // ||{
218
- quick_thread ( || {
219
- let callable = unsafe { crosser. extract ( ) } ;
220
- callable. callv ( & varray ! [ 5 ] ) ;
221
- } ) ;
222
- // ,);
214
+ // Why expect_panic for (single-threaded && Debug) but not (multi-threaded || Release) mode:
215
+ // - Check is only enabled in Debug, not Release.
216
+ // - We currently can't catch panics from Callable invocations, see above. True for both single/multi-threaded.
217
+ // - In single-threaded mode, there's an FFI access check which panics as soon as another thread is invoked. *This* panics.
218
+ // - In multi-threaded, we need to observe the effect instead (see below).
219
+
220
+ if !cfg ! ( feature = "experimental-threads" ) && cfg ! ( debug_assertions) {
221
+ // Single-threaded and Debug.
222
+ crate :: framework:: expect_panic (
223
+ "Callable created with from_local_fn() must panic when invoked on other thread" ,
224
+ || {
225
+ quick_thread ( || {
226
+ let callable = unsafe { crosser. extract ( ) } ;
227
+ callable. callv ( & varray ! [ 5 ] ) ;
228
+ } ) ;
229
+ } ,
230
+ ) ;
231
+ } else {
232
+ // Multi-threaded OR Release.
233
+ quick_thread ( || {
234
+ let callable = unsafe { crosser. extract ( ) } ;
235
+ callable. callv ( & varray ! [ 5 ] ) ;
236
+ } ) ;
237
+ }
223
238
224
- // We should really use expect_panic here (AROUND quick_thread, not inside), however we currently can't catch panics, see above.
225
- // Instead, we check the global value.
226
239
assert_eq ! (
227
240
* GLOBAL . lock( ) ,
228
241
0 ,
0 commit comments