rusty_v8
rusty_v8 copied to clipboard
Unsoundness when starting an isolate per thread
Is it supposed to be sound to instantiate one isolate per thread? If it's not the API shouldn't allow it.
If it is, you have data races as reported by ThreadSanitizer at least when creating and dropping the isolates.
There are more data races reported by it.
use std::sync::Once;
fn main() {
fn init_isolate() {
// Init isolate
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
}
static START: Once = Once::new();
START.call_once(|| {
let platform = v8::new_default_platform(0, false).make_shared();
v8::V8::initialize_platform(platform);
v8::V8::initialize();
});
for _ in 0..16 {
std::thread::spawn(move || {
init_isolate();
});
}
}
This code can be ran with RUSTFLAGS=-Zsanitizer=thread cargo +nightly run -r -Zbuild-std --target x86_64-unknown-linux-gnu