Skip to content
Snippets Groups Projects
Commit ca87219e authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Added membed tutorial

parent 4cc8c691
Branches
Tags
No related merge requests found
target target
*~
embed/node_modules
[root]
name = "embed"
version = "0.1.0"
[package]
name = "embed"
version = "0.1.0"
authors = ["Anders Nilsson <anders.nilsson@control.lth.se>"]
[lib]
name ="embed"
crate-type = ["dylib"]
var ffi = require('ffi');
var lib = ffi.Library('../target/release/libembed', {
'process': ['void', []]
});
lib.process();
console.log("done!");
from ctypes import cdll
lib = cdll.LoadLibrary("../target/release/libembed.so")
lib.process()
print("done!")
require 'ffi'
module Hello
extend FFI::Library
ffi_lib '../target/release/libembed.so'
attach_function :process, [], :void
end
Hello.process
puts 'done!'
use std::thread;
#[no_mangle]
pub extern fn process() {
let handles: Vec<_> = (0..10).map(|_| {
thread::spawn(|| {
let mut x = 0;
for _ in (0..15_000_000) {
x += 1
}
x
})
}).collect();
for h in handles {
println!("Thread finished with count={}",h.join().map_err(|_|"Could not join a thread!").unwrap());
}
println!("done!");
}
threads = []
10.times do
threads << Thread.new do
count = 0
15_000_000.times do
count += 1
end
count
end
end
threads.each do |t|
puts "Thread finished with count=#{t.value}"
end
puts "done!"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment