Skip to content

Instantly share code, notes, and snippets.

@Ms2ger
Last active October 23, 2015 12:17
Show Gist options
  • Save Ms2ger/d21f605b0636139f4fb9 to your computer and use it in GitHub Desktop.
Save Ms2ger/d21f605b0636139f4fb9 to your computer and use it in GitHub Desktop.
jsapi threading
[package]
name = "test"
version = "0.1.0"
authors = ["Ms2ger <Ms2ger@gmail.com>"]
[[bin]]
path = "main.rs"
name = "test"
[dependencies.js]
git = "https://github.com/servo/rust-mozjs"
features = ["debugmozjs"]
extern crate js;
use js::jsapi::{JS_Init, JS_NewRuntime};
use std::thread;
use std::ptr;
fn create_runtime() {
unsafe {
JS_NewRuntime(0x2000000, 0x100000, ptr::null_mut());
}
println!("Created");
}
fn main() {
println!("Hello, world!");
assert!(unsafe { JS_Init() });
let x = thread::spawn(create_runtime);
let y = thread::spawn(create_runtime);
let z = thread::spawn(create_runtime);
x.join().unwrap();
y.join().unwrap();
z.join().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment