Skip to content

Instantly share code, notes, and snippets.

@papriwal-prateek
Created October 12, 2015 03:53
Show Gist options
  • Save papriwal-prateek/e9083791f1027f630c06 to your computer and use it in GitHub Desktop.
Save papriwal-prateek/e9083791f1027f630c06 to your computer and use it in GitHub Desktop.
RSpec.describe V8Eval, '#multithreading' do
context 'with multithread execution' do
it 'should execute concurrently' do
# V8Thread is a thread which runs a V8 instance.
class V8Thread
def initialize(num)
@num_repeat = num
@v8 = V8Eval::V8.new
@counter = 0
end
def eval_v8
thread = Thread.new do
@v8.eval('function inc(x) { return x + 1; }')
@num_repeat.times do
@counter = @v8.call('inc', [@counter])
puts @counter
end
expect(@counter).to eq(@num_repeat)
end
return thread
end
end
num_repeat = 10000
thread1 = V8Thread.new(num_repeat).eval_v8
thread2 = V8Thread.new(num_repeat).eval_v8
thread1.join
thread2.join
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment