atomic 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -46
- data/atomic.gemspec +6 -5
- metadata +33 -34
data/README.rdoc
CHANGED
@@ -6,58 +6,38 @@ This library provides:
|
|
6
6
|
|
7
7
|
* an Atomic class that guarantees atomic updates to its contained value
|
8
8
|
|
9
|
-
The Atomic class provides accessors for the contained "value" plus two update
|
10
|
-
methods:
|
9
|
+
The Atomic class provides accessors for the contained "value" plus two update methods:
|
11
10
|
|
12
|
-
* update will run the provided block, passing the current value and replacing
|
13
|
-
|
14
|
-
It may run the block repeatedly if there are other concurrent updates in
|
15
|
-
progress.
|
16
|
-
* try_update will run the provided block, passing the current value and
|
17
|
-
replacing it with the block result. If the value changes before the update
|
18
|
-
can happen, it will throw Atomic::ConcurrentUpdateError.
|
11
|
+
* update will run the provided block, passing the current value and replacing it with the block result iff the value has not been changed in the mean time. It may run the block repeatedly if there are other concurrent updates in progress.
|
12
|
+
* try_update will run the provided block, passing the current value and replacing it with the block result. If the value changes before the update can happen, it will throw Atomic::ConcurrentUpdateError.
|
19
13
|
|
20
14
|
The atomic repository is at http://github.com/headius/ruby-atomic.
|
21
15
|
|
22
|
-
|
23
16
|
== Usage
|
24
17
|
|
25
|
-
The simplest way to use "atomic" is to call the "update" or "try_update"
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
It's also possible to use the regular get/set operations on the Atomic, if you
|
48
|
-
want to avoid the exception and respond to contended changes in some other way.
|
49
|
-
|
50
|
-
````ruby
|
51
|
-
my_atomic = Atomic.new(0)
|
52
|
-
my_atomic.value # => 0
|
53
|
-
my_atomic.value = 1
|
54
|
-
my_atomic.swap(2) # => 1
|
55
|
-
my_atomic.compare_and_swap(2, 3) # => true, updated to 3
|
56
|
-
my_atomic.compare_and_swap(2, 3) # => false, current is not 2
|
57
|
-
````
|
18
|
+
The simplest way to use "atomic" is to call the "update" or "try_update" methods.
|
19
|
+
|
20
|
+
"try_update" and "update" both call the given block, passing the current value and using the block's result as the new value. If the value is updated by another thread before the block completes, "try update" raises a ConcurrentUpdateError and "update" retries the block. Because "update" may call the block several times when multiple threads are all updating the same value, the block's logic should be kept as simple as possible.
|
21
|
+
|
22
|
+
require 'atomic'
|
23
|
+
|
24
|
+
my_atomic = Atomic.new(0)
|
25
|
+
my_atomic.update {|v| v + 1}
|
26
|
+
begin
|
27
|
+
my_atomic.try_update {|v| v + 1}
|
28
|
+
rescue Atomic::ConcurrentUpdateError => cue
|
29
|
+
# deal with it (retry, propagate, etc)
|
30
|
+
end
|
31
|
+
|
32
|
+
It's also possible to use the regular get/set operations on the Atomic, if you want to avoid the exception and respond to contended changes in some other way.
|
33
|
+
|
34
|
+
my_atomic = Atomic.new(0)
|
35
|
+
my_atomic.value # => 0
|
36
|
+
my_atomic.value = 1
|
37
|
+
my_atomic.swap(2) # => 1
|
38
|
+
my_atomic.compare_and_swap(2, 3) # => true, updated to 3
|
39
|
+
my_atomic.compare_and_swap(2, 3) # => false, current is not 2
|
58
40
|
|
59
41
|
== Building
|
60
42
|
|
61
|
-
As of 1.1.0, JDK8 is required to build the atomic gem, since it attempts to use
|
62
|
-
the new atomic Unsafe.getAndSetObject method only in JDK8. The resulting code
|
63
|
-
should still work fine as far back as Java 5.
|
43
|
+
As of 1.1.0, JDK8 is required to build the atomic gem, since it attempts to use the new atomic Unsafe.getAndSetObject method only in JDK8. The resulting code should still work fine as far back as Java 5.
|
data/atomic.gemspec
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
# Update these to get proper version and commit history
|
4
|
-
new_version = "1.1.
|
4
|
+
new_version = "1.1.4"
|
5
5
|
old_version = "1.1.0"
|
6
6
|
|
7
|
-
|
7
|
+
git_lines = `git log --oneline #{old_version}...#{new_version}`.lines.map {|str| "* #{str}"}.join
|
8
|
+
doc_lines = File.readlines("README.rdoc")
|
8
9
|
description = <<EOS
|
9
|
-
#{
|
10
|
+
#{doc_lines[0]}
|
10
11
|
|
11
12
|
== Changes since #{old_version}
|
12
13
|
|
13
|
-
#{
|
14
|
-
#{
|
14
|
+
#{git_lines}
|
15
|
+
#{doc_lines[2..-1].join("\n")}
|
15
16
|
EOS
|
16
17
|
|
17
18
|
Gem::Specification.new do |s|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atomic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,39 +14,38 @@ cert_chain: []
|
|
14
14
|
date: 2013-04-05 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: ! "= An atomic reference implementation for JRuby, Rubinius, and MRI.\n\n\n==
|
17
|
-
Changes since 1.1.0\n\
|
18
|
-
to
|
19
|
-
|
20
|
-
to
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
the block
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
3) # =>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
Java 5.\n"
|
17
|
+
Changes since 1.1.0\n\n* a574b34 More formatting for description.\n* 58d3e34 Convert
|
18
|
+
README to rdoc and try again.\n* f519385 Attempting to get description to look nice
|
19
|
+
on rubygems.org.\n* 2c5ab6c Include README and oneline logs in gem description.\n*
|
20
|
+
6aeb053 Add @funny-falcon to authors.\n* aa24d4d Bump version to 1.1.1.\n* dc327eb
|
21
|
+
Merge pull request #16 from funny-falcon/patch-1\n* 1b68767 Fix JRUBYREFERENCE8_ALLOCATOR\n\n==
|
22
|
+
Summary\n\n\n\nThis library provides:\n\n\n\n* an Atomic class that guarantees atomic
|
23
|
+
updates to its contained value\n\n\n\nThe Atomic class provides accessors for the
|
24
|
+
contained \"value\" plus two update methods:\n\n\n\n* update will run the provided
|
25
|
+
block, passing the current value and replacing it with the block result iff the
|
26
|
+
value has not been changed in the mean time. It may run the block repeatedly if
|
27
|
+
there are other concurrent updates in progress.\n\n* try_update will run the provided
|
28
|
+
block, passing the current value and replacing it with the block result. If the
|
29
|
+
value changes before the update can happen, it will throw Atomic::ConcurrentUpdateError.\n\n\n\nThe
|
30
|
+
atomic repository is at http://github.com/headius/ruby-atomic.\n\n\n\n== Usage\n\n\n\nThe
|
31
|
+
simplest way to use \"atomic\" is to call the \"update\" or \"try_update\" methods.\n\n\n\n\"try_update\"
|
32
|
+
and \"update\" both call the given block, passing the current value and using the
|
33
|
+
block's result as the new value. If the value is updated by another thread before
|
34
|
+
the block completes, \"try update\" raises a ConcurrentUpdateError and \"update\"
|
35
|
+
retries the block. Because \"update\" may call the block several times when multiple
|
36
|
+
threads are all updating the same value, the block's logic should be kept as simple
|
37
|
+
as possible.\n\n\n\n require 'atomic'\n\n\n\n my_atomic = Atomic.new(0)\n\n
|
38
|
+
\ my_atomic.update {|v| v + 1}\n\n begin\n\n my_atomic.try_update {|v|
|
39
|
+
v + 1}\n\n rescue Atomic::ConcurrentUpdateError => cue\n\n # deal with it
|
40
|
+
(retry, propagate, etc)\n\n end\n\n\n\nIt's also possible to use the regular
|
41
|
+
get/set operations on the Atomic, if you want to avoid the exception and respond
|
42
|
+
to contended changes in some other way.\n\n\n\n my_atomic = Atomic.new(0)\n\n
|
43
|
+
\ my_atomic.value # => 0\n\n my_atomic.value = 1\n\n my_atomic.swap(2) #
|
44
|
+
=> 1\n\n my_atomic.compare_and_swap(2, 3) # => true, updated to 3\n\n my_atomic.compare_and_swap(2,
|
45
|
+
3) # => false, current is not 2\n\n\n\n== Building\n\n\n\nAs of 1.1.0, JDK8 is required
|
46
|
+
to build the atomic gem, since it attempts to use the new atomic Unsafe.getAndSetObject
|
47
|
+
method only in JDK8. The resulting code should still work fine as far back as Java
|
48
|
+
5.\n"
|
50
49
|
email:
|
51
50
|
- headius@headius.com
|
52
51
|
- mental@rydia.net
|