Skip to content

Commit 9341b09

Browse files
committed
Updated example scripts.
1 parent 1c11cde commit 9341b09

7 files changed

+41
-6
lines changed

examples/at_exit_tester.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
3+
$: << File.expand_path('../../lib', __FILE__)
4+
5+
require 'concurrent'
6+
7+
# with this, a JRuby process will never exit
8+
Concurrent.disable_auto_termination_of_all_executors!
9+
10+
SIZE = 5
11+
12+
pool = Concurrent::FixedThreadPool.new(SIZE)
13+
14+
latch = Concurrent::CountDownLatch.new(SIZE)
15+
16+
print "Posting #{SIZE} tasks...\n"
17+
18+
SIZE.times do |i|
19+
pool.post do
20+
this = i
21+
sleep(1)
22+
print "Completing task #{i}\n"
23+
latch.count_down
24+
end
25+
end
26+
27+
print "Waiting for all tasks to complete...\n"
28+
latch.wait
29+
print "Done\n"

examples/atomic_example.rb

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#!/usr/bin/env ruby
2+
3+
$: << File.expand_path('../../lib', __FILE__)
4+
15
require 'concurrent/atomic'
26

37
my_atomic = Concurrent::Atomic.new(0)

examples/benchmark_atomic_boolean.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22

3-
$:.push File.join(File.dirname(__FILE__), '../lib')
3+
$: << File.expand_path('../../lib', __FILE__)
44

55
require 'concurrent/atomics'
66
require 'benchmark'

examples/benchmark_atomic_fixnum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22

3-
$:.push File.join(File.dirname(__FILE__), '../lib')
3+
$: << File.expand_path('../../lib', __FILE__)
44

55
require 'concurrent/atomics'
66
require 'benchmark'

examples/benchmark_read_write_lock.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22

3-
$:.push File.join(File.dirname(__FILE__), '../lib')
3+
$: << File.expand_path('../../lib', __FILE__)
44

55
require 'concurrent/atomic/read_write_lock'
66
require 'benchmark'

examples/graph_atomic_bench.rb

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env ruby
22

3+
$: << File.expand_path('../../lib', __FILE__)
4+
35
require 'optparse'
46

57
conf = {
@@ -35,7 +37,7 @@
3537

3638
ret = []
3739
10.times do
38-
ret << `ruby ./bench_atomic_1.rb -l #{conf[:lock]} -t #{i}`.to_f
40+
ret << `ruby #{File.dirname(__FILE__)}/bench_atomic_1.rb -l #{conf[:lock]} -t #{i}`.to_f
3941
end
4042

4143
line = ([i] + ret).join(', ')
@@ -58,7 +60,7 @@
5860

5961
ret = []
6062
10.times do
61-
ret << `ruby ./bench_atomic_1.rb -l #{conf[:lock]} -s #{i}`.to_f
63+
ret << `ruby #{File.dirname(__FILE__)}/bench_atomic_1.rb -l #{conf[:lock]} -s #{i}`.to_f
6264
end
6365

6466
line = ([i] + ret).join(', ')

examples/test_clock_variations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22

3-
$: << File.expand_path('./lib', __FILE__)
3+
$: << File.expand_path('../../lib', __FILE__)
44

55
require 'benchmark'
66
require 'thread'

0 commit comments

Comments
 (0)