Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support synchronized #221

Open
ribrdb opened this Issue · 7 comments

6 participants

@ribrdb
Owner

No description provided.

@baroquebobcat

How would we like to support synchronized?

It could act like public / protected / private

class A
  synchronized
  def foo; end
  def bar; end
end

Or class method style, which is compatible w/ above

class A
  synchronized :foo, :bar
  def foo; end
  def bar; end
end

or modifier on def ala Java Scala--not as Rubyish though

class A
  synchronized def foo; end
  synchronized def bar; end
end
@shannah

If you did option 1, how would you specify the end of the "synchronized" section of methods? Or would synchronized methods always have to be implemented in the last part of the class?

As a java dev, I'm biased towards option 3.

@sdwolf

I like the second one the most (personaly rubyist preference) but have no arguments against the other 2.
The third one does indeed feel the most java-like (and it should probably be like this).

@ribrdb
Owner

My preference is (3). Should we also support synchronized blocks inside a method?

 synchronized (x) { x.a; x.b }
@Axianator
Owner

Personally, I think option (1) is the most Rubyish, but option (3) is probably the better way to go.

If you could give users the choice between placing the synchronized call either inline with the method definition or on it's own newline outside the method (like option 1), that would be even better:

# Inline with method
synchronized def foo; puts 'This works!'; end

# Outside method on newline
synchronized
def foo
  puts 'So does this!'
end
@KeenS

AFAIK current ruby allows all of three. Method definitions have been changed to return its method name to allow (3) since ruby 2.1 (see this).
Is it possible to support all of three?

@baroquebobcat

Once support for public / protected / private goes in, the same mechanism could be extended to synchronize I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.