Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race conditions with multiple threads in context #6

Closed
wants to merge 1 commit into from

Conversation

asenchi
Copy link
Owner

@asenchi asenchi commented Apr 26, 2012

This is my first attempt. Honestly, I don't have a lot of experience around multi-threaded programming, so this may be messy (it seems clunky to me, but that's only a gut feeling).

Going to work on a better way to test this, and see if there are improvements that I can make.

@asenchi
Copy link
Owner Author

asenchi commented Apr 26, 2012

I produced this test:

#!/usr/bin/env ruby

$: << "./lib"

require 'scrolls'

Scrolls::Log.start

Scrolls.context(:global => "g")

def test_method1
  i = 0
  while i <= 5
    Scrolls.context(:method => "test_method1") do
      Scrolls.log(:data => i)
    end
    sleep 2
    i = i + 1
  end
end

def test_method2
  i = 0
  while i <= 5
    Scrolls.context(:method => "test_method2") do
      Scrolls.context(:around => "a") do
        Scrolls.log(:data => i)
      end
    end
    sleep 2
    i = i + 1
  end
end

Scrolls.log(:start => :treads) do
  t1 = Thread.new { test_method1() }
  t2 = Thread.new { test_method2() }
  t1.join
  t2.join
end

The code in this PR does not pass the test.

@asenchi
Copy link
Owner Author

asenchi commented Apr 26, 2012

@fabiokung posted working code in #7, closing this as it doesn't work as intended.

@asenchi asenchi closed this Apr 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant