Skip to content

Instantly share code, notes, and snippets.

@jkutner
Last active December 20, 2015 02:29
Show Gist options
  • Save jkutner/6056579 to your computer and use it in GitHub Desktop.
Save jkutner/6056579 to your computer and use it in GitHub Desktop.
i = size+1
realloc(i)
set(i, val)
config.filter_parameters += [:password]
data << m * n
class ExpensiveToCreate
def self.instance
@instance ||= ExpensiveToCreate.new
end
end
$ jrlint
./config/application.rb:54: [nonatomic, warning] Non-local operator assignment is not guaranteed to be atomic
$ jruby threads.rb
size => 182
$ ruby threads.rb
size => 256
/** rb_ary_push - specialized rb_ary_store
*
*/
@JRubyMethod(name = "<<", required = 1)
public RubyArray append(IRubyObject item) {
modify();
int valuesLength = values.length - begin;
if (realLength == valuesLength) {
if (realLength == Integer.MAX_VALUE) throw getRuntime().newArgumentError("index too big");
long newLength = valuesLength + (valuesLength >> 1);
if (newLength > Integer.MAX_VALUE) {
newLength = Integer.MAX_VALUE;
} else if (newLength < ARRAY_DEFAULT_SIZE) {
newLength = ARRAY_DEFAULT_SIZE;
}
realloc((int) newLength, valuesLength);
}
safeArraySet(values, begin + realLength++, item);
return this;
}
data = []
threads = []
16.times do |m|
threads << Thread.new do
16.times do |n|
data << m * n
end
end
end
threads.map(&:join)
puts "size => #{data.size}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment