atomic_hamster 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +37 -0
- data/Rakefile +8 -0
- data/atomic_hamster.gemspec +16 -0
- data/lib/atomic_hamster.rb +2 -0
- data/spec/atomic_hamster_spec.rb +22 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e24eca7c89590dd70dddcc3f5ad1c9a2ebdcbc77
|
4
|
+
data.tar.gz: 17a01926872b7f15ff3b0d7dc6dbbf2b116d13f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f59427384abcea1569f67626b13a5eee80be72d413ad541a408fdd3451f2fc3035bff9d508f4aa19f8320dd490c0107b6cb8e123418ffead237bb922bbbd346a
|
7
|
+
data.tar.gz: e2f2fc9370d93ea16347e96b27fb188afd9214ff9e57b01fd2715a87fc5a6a2cb87f95e4b2963c65b40a261bdb7fad4dc4cfbdf91e4a6f64d4fad523fa919a5b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Atomic Hamster
|
2
|
+
|
3
|
+
> Because naming things is sometimes funny.
|
4
|
+
|
5
|
+
We have:
|
6
|
+
|
7
|
+
- [Atomic](http://rubygems.org/gems/atomic): <https://github.com/headius/ruby-atomic>
|
8
|
+
|
9
|
+
An atomic reference implementation for JRuby, Rubinius, and MRI.
|
10
|
+
|
11
|
+
- [Hamster](http://rubygems.org/gems/hamster): <https://github.com/harukizaemon/hamster>
|
12
|
+
|
13
|
+
Efficient, Immutable, Thread-Safe Collection classes for Ruby.
|
14
|
+
|
15
|
+
When writing threaded code, the [Atomic](http://rubygems.org/gems/atomic)[ ](http://rubygems.org/gems/atomic_hamster)[Hamster](http://rubygems.org/gems/hamster) guards and protects your shared mutable state.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require "atomic_hamster"
|
19
|
+
|
20
|
+
container = Atomic.new(Hamster.list)
|
21
|
+
iterations = 1_000
|
22
|
+
|
23
|
+
iterations.times.map do |i|
|
24
|
+
Thread.new do
|
25
|
+
sleep(rand)
|
26
|
+
container.update do |list|
|
27
|
+
list.cons(i)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end.map(&:join)
|
31
|
+
|
32
|
+
puts container.value.length # => 1000
|
33
|
+
```
|
34
|
+
|
35
|
+
## Credits
|
36
|
+
|
37
|
+
All credits go to the [Atomic](http://rubygems.org/gems/atomic)[ ](http://rubygems.org/gems/atomic_hamster)[Hamster](http://rubygems.org/gems/hamster). I did not do anything.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "atomic_hamster"
|
4
|
+
spec.version = "1.0.0"
|
5
|
+
spec.authors = ["Kim Burgestrand"]
|
6
|
+
spec.email = ["kim@burgestrand.se"]
|
7
|
+
spec.summary = %q{Because naming things is sometimes funny.}
|
8
|
+
spec.licenses = ["MIT", "Apache 2.0"]
|
9
|
+
|
10
|
+
spec.files = `git ls-files`.split($/)
|
11
|
+
spec.require_paths = ["lib"]
|
12
|
+
|
13
|
+
spec.add_runtime_dependency "atomic"
|
14
|
+
spec.add_runtime_dependency "hamster"
|
15
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "atomic_hamster"
|
3
|
+
|
4
|
+
container = Atomic.new(Hamster.list)
|
5
|
+
iterations = 1_000
|
6
|
+
|
7
|
+
iterations.times.map do |i|
|
8
|
+
Thread.new do
|
9
|
+
sleep(rand)
|
10
|
+
container.update do |list|
|
11
|
+
list.cons(i)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end.map(&:join)
|
15
|
+
|
16
|
+
if container.value.length == iterations
|
17
|
+
$stderr.puts "Atomic Hamster succeeds spectacularly."
|
18
|
+
exit true
|
19
|
+
else
|
20
|
+
$stderr.puts "Atomic Hamster fails humbly with a stunning #{container.value.length} of #{iterations}."
|
21
|
+
exit false
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: atomic_hamster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kim Burgestrand
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: atomic
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hamster
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- kim@burgestrand.se
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- atomic_hamster.gemspec
|
67
|
+
- lib/atomic_hamster.rb
|
68
|
+
- spec/atomic_hamster_spec.rb
|
69
|
+
homepage:
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
- Apache 2.0
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.5
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Because naming things is sometimes funny.
|
94
|
+
test_files: []
|
95
|
+
has_rdoc:
|