Sha256: 4ead03755904b0b62ed0c059e70475a748a9879274a55343baaf75086f669e14

Contents?: true

Size: 1.29 KB

Versions: 28

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe "using v8 from multiple threads", :threads => true do

  it "creates contexts from within threads" do
    10.times.collect do
      Thread.new do
        V8::Context.new
      end
    end.each {|t| t.join}
    V8::Context.new
  end

  it "executes codes on multiple threads simultaneously" do
    5.times.collect{V8::Context.new}.collect do |ctx|
      Thread.new do
        ctx['x'] = 99
        while ctx['x'] > 0
          ctx.eval 'for (i=10000;i;i--){};--x'
        end
      end
    end.each {|t| t.join}
  end

  it "can access the current thread id" do
    V8::C::Locker() do
      V8::C::V8::GetCurrentThreadId().should_not be_nil
    end
  end

  it "can pre-empt a running JavaScript thread" do
    pending "need to release the GIL while executing V8 code"
    begin
      V8::C::Locker::StartPreemption(2)
      thread_id = nil
      Thread.new do
        loop until thread_id
        puts "thread id: #{thread_id}"
        V8::C::V8::TerminateExecution(thread_id)
      end
      Thread.new do
        V8::C::Locker() do
          thread_id = V8::C::V8::GetCurrentThreadId()
          V8::Context.new {|cxt| cxt.eval('while (true) {}')}
        end
      end
      V8::C::V8::TerminateExecution(thread_id)
    ensure
      V8::C::Locker::StopPreemption()
    end
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/therubyracer-0.11.4/spec/threading_spec.rb
therubyracer-0.12.0 spec/threading_spec.rb
therubyracer-0.11.4 spec/threading_spec.rb
therubyracer-0.11.3 spec/threading_spec.rb
therubyracer-0.11.2 spec/threading_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.11.0/spec/threading_spec.rb
therubyracer-0.11.1 spec/threading_spec.rb
therubyracer-0.11.1beta1 spec/threading_spec.rb
therubyracer-0.11.0 spec/threading_spec.rb
therubyracer-0.11.0beta8-x86-freebsd-9 spec/threading_spec.rb
therubyracer-0.11.0beta8-x86_64-linux spec/threading_spec.rb
therubyracer-0.11.0beta8-x86-linux spec/threading_spec.rb
therubyracer-0.11.0beta8 spec/threading_spec.rb
therubyracer-0.11.0beta7-x86_64-linux spec/threading_spec.rb
therubyracer-0.11.0beta7-x86-linux spec/threading_spec.rb
therubyracer-0.11.0beta7-x86_64-darwin-10 spec/threading_spec.rb
therubyracer-0.11.0beta7 spec/threading_spec.rb
therubyracer-0.11.0beta6-x86-linux spec/threading_spec.rb
therubyracer-0.11.0beta6-x86_64-linux spec/threading_spec.rb
therubyracer-0.11.0beta6 spec/threading_spec.rb