Sha256: 0bf095d308f042ad2e6868447996c13f73556a40d37d12769dfa40289faba5e0

Contents?: true

Size: 986 Bytes

Versions: 2614

Compression:

Stored size: 986 Bytes

Contents

require 'ffi'

module LibC
  extend FFI::Library
  ffi_lib FFI::Library::LIBC
  callback :qsort_cmp, [ :pointer, :pointer ], :int
  attach_function :qsort, [ :pointer, :ulong, :ulong, :qsort_cmp ], :int

  freeze # Freeze the module variables, so that it can be shared across ractors.
end

p = FFI::MemoryPointer.new(:int, 3)
p.put_array_of_int32(0, [ 2, 3, 1 ])   # Write some unsorted data into the memory
# Ractor.make_shareable(p)             # freeze the pointer to be shared between ractors instead of copied
puts "main  -ptr=#{p.inspect}"
res = Ractor.new(p) do |p|
  puts "ractor-ptr=#{p.inspect}"
  puts "Before qsort #{p.get_array_of_int32(0, 3).join(', ')}"
  LibC.qsort(p, 3, 4) do |p1, p2|
    i1 = p1.get_int32(0)
    i2 = p2.get_int32(0)
    puts "In block: comparing #{i1} and #{i2}"
    i1 < i2 ? -1 : i1 > i2 ? 1 : 0
  end
  puts "After qsort #{p.get_array_of_int32(0, 3).join(', ')}"
end.take

puts "After ractor termination #{p.get_array_of_int32(0, 3).join(', ')}"

Version data entries

2,614 entries across 2,614 versions & 21 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/ffi-1.16.3/samples/qsort_ractor.rb
cybrid_api_bank_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_organization_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_id_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_bank_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_organization_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_id_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_id_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_bank_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_organization_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_organization_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_id_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_bank_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
ory-client-1.15.12 vendor/bundle/ruby/3.1.0/gems/ffi-1.17.0/samples/qsort_ractor.rb
cybrid_api_bank_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_id_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_organization_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_bank_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_organization_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb
cybrid_api_id_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ffi-1.17.0-x86_64-linux-gnu/samples/qsort_ractor.rb