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

Already on GitHub? Sign in to your account

Support synchronized #221

Closed
ribrdb opened this Issue May 23, 2013 · 7 comments

Comments

Projects
None yet
6 participants
Contributor

ribrdb commented May 23, 2013

No description provided.

Owner

baroquebobcat commented Jan 21, 2015

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
Contributor

shannah commented Jan 21, 2015

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 commented Jan 21, 2015

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).

Contributor

ribrdb commented Jan 21, 2015

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

 synchronized (x) { x.a; x.b }

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
Contributor

KeenS commented Jan 22, 2015

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?

Owner

baroquebobcat commented Jan 23, 2015

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

felixvf pushed a commit to felixvf/mirah that referenced this issue Apr 16, 2015

felixvf pushed a commit to felixvf/mirah that referenced this issue Apr 28, 2015

@felixvf felixvf closed this in 1f506d8 Jul 23, 2015

felixvf added a commit that referenced this issue Jul 23, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment