masover-threadsafe 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +9 -0
  2. data/lib/threadsafe.rb +20 -0
  3. metadata +54 -0
data/README ADDED
@@ -0,0 +1,9 @@
1
+ Right now, all this does is add a method called threadsafe? to Object, which returns false.
2
+
3
+ The idea is that if you know an object is threadsafe, you can just use it, without worrying about synchronization. If the object is not threadsafe, you know you have to synchronize access. This provides a means of doing that programmatically.
4
+
5
+ In this case, "threadsafe" is defined as "every method call is atomic", meaning it either handles synchronization itself, or synchronization isn't needed. It is allowed for an object to change from non-threadsafe to threadsafe, but not vice versa.
6
+
7
+ This is something I wanted for an actor library I'm developing. The idea is that unsafe objects can be automatically wrapped in actors, but it would be nice to avoid wrapping known-safe objects in actors.
8
+
9
+ However, I have no idea what's safe, so contributions welcome!
data/lib/threadsafe.rb ADDED
@@ -0,0 +1,20 @@
1
+ # Only put core objects here.
2
+ # Additional libraries should define threadsafe-ness for themselves.
3
+ # (Otherwise, we'd either have to require them here, or intercept every
4
+ # require, which we can't do until autoload is fixed.)
5
+
6
+ {
7
+ # Default to false
8
+ Object => false
9
+ }.each_pair do |klass, safe|
10
+ klass.class_eval do
11
+ unless method_defined? :threadsafe?
12
+ # Hack to avoid define_method overhead
13
+ if safe
14
+ def threadsafe?; true; end
15
+ else
16
+ def threadsafe?; false; end
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: masover-threadsafe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - David Masover
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: dave@3mix.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - lib/threadsafe.rb
27
+ has_rdoc: false
28
+ homepage:
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: "0"
39
+ version:
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.2.0
50
+ signing_key:
51
+ specification_version: 2
52
+ summary: "Adds a #threadsafe? method to Ruby classes."
53
+ test_files: []
54
+