@@ -7779,7 +7779,6 @@ def test_embind_val_assignment(self):
7779
7779
@node_pthreads
7780
7780
def test_embind_val_cross_thread (self ):
7781
7781
self .emcc_args += ['--bind' ]
7782
- self .setup_node_pthreads ()
7783
7782
create_file ('test_embind_val_cross_thread.cpp' , r'''
7784
7783
#include <emscripten.h>
7785
7784
#include <emscripten/val.h>
@@ -7804,6 +7803,34 @@ def test_embind_val_cross_thread(self):
7804
7803
''' )
7805
7804
self .do_runf ('test_embind_val_cross_thread.cpp' , 'val accessed from wrong thread' , assert_returncode = NON_ZERO )
7806
7805
7806
+ @node_pthreads
7807
+ def test_embind_val_cross_thread_deleted (self ):
7808
+ self .emcc_args += ['--bind' ]
7809
+ create_file ('test_embind_val_cross_thread.cpp' , r'''
7810
+ #include <emscripten.h>
7811
+ #include <emscripten/val.h>
7812
+ #include <thread>
7813
+ #include <stdio.h>
7814
+ #include <optional>
7815
+
7816
+ using emscripten::val;
7817
+
7818
+ int main(int argc, char **argv) {
7819
+ // Create a storage for value handles on the main thread.
7820
+ std::optional<val> opt_value;
7821
+ std::thread([&] {
7822
+ // Set to a value handle from a different thread.
7823
+ val& value = opt_value.emplace(1);
7824
+ // Move out from the optional storage so that we free the value on the same thread.
7825
+ val moved_out = std::move(value);
7826
+ }).join();
7827
+ // Now std::optional is initialized but with a deleted value handle.
7828
+ // There should be no cross-thread error here when it tries to free that value,
7829
+ // because the value has already been deleted on the correct thread.
7830
+ }
7831
+ ''' )
7832
+ self .do_runf ('test_embind_val_cross_thread.cpp' )
7833
+
7807
7834
def test_embind_dynamic_initialization (self ):
7808
7835
self .emcc_args += ['-lembind' ]
7809
7836
self .do_run_in_out_file_test ('embind/test_dynamic_initialization.cpp' )
0 commit comments