process_shared 0.2.1b → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -13
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23ff1b1fbc2944e69e66f89d2db7dc0210cfd95
|
4
|
+
data.tar.gz: d361bd34750fc4ee8f099fbc7d7be73fb753002d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4fd2807a7fa4bf0863ba329a45cc3e05fb3abb74ccd7492dfa53c214bf7493eeb75d3646143e63aee3f8fae484ab162d0ef7cdf4fbfc38f252824f7f878d597
|
7
|
+
data.tar.gz: 1079a54be971d445ef46eaa06fd228616668a49a79dfdac25ea56eab111a10b30e75b5dd628aeab1fc5d1401ef82bd0d5526870363cf741791605da5e7f5b3a8
|
data/README.md
CHANGED
@@ -14,26 +14,57 @@
|
|
14
14
|
process_shared
|
15
15
|
==============
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
Cross-process concurrency primitives that may be used to coordinate
|
18
|
+
shared memory between processes.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'process_shared'
|
22
|
+
|
23
|
+
mutex = ProcessShared::Mutex.new
|
24
|
+
cond = ProcessShared::ConditionVariable.new
|
25
|
+
|
26
|
+
mem = ProcessShared::SharedMemory.new(:int32, 2) # extends FFI::Pointer
|
27
|
+
|
28
|
+
pid1 = fork do
|
29
|
+
nums = mutex.synchronize do
|
30
|
+
cond.wait(mutex)
|
31
|
+
mem.get_array_of_int(0, 2)
|
32
|
+
end
|
33
|
+
puts "process #{Process.pid} received #{nums}"
|
34
|
+
end
|
35
|
+
|
36
|
+
pid2 = fork do
|
37
|
+
nums = [12345, 67890]
|
38
|
+
mutex.synchronize do
|
39
|
+
puts "process #{Process.pid} sending #{nums}"
|
40
|
+
mem.put_array_of_int(0, nums)
|
41
|
+
cond.signal
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Process.waitall
|
46
|
+
```
|
47
|
+
|
48
|
+
[API Documentation](http://www.rubydoc.info/github/pmahoney/process_shared/master)
|
19
49
|
|
20
50
|
FFI is used to access POSIX semaphore on Linux or Mach semaphores on
|
21
|
-
Mac.
|
22
|
-
ProcessShared::Mutex
|
23
|
-
ProcessShared::SharedMemory
|
51
|
+
Mac. Atop these semaphores are implemented `ProcessShared::Semaphore`,
|
52
|
+
`ProcessShared::Mutex`. POSIX shared memory is used to implement
|
53
|
+
`ProcessShared::SharedMemory`.
|
24
54
|
|
25
55
|
On Linux, POSIX semaphores support `sem_timedwait()` which can wait on
|
26
56
|
a semaphore but stop waiting after a timeout.
|
27
57
|
|
28
58
|
Mac OS X's implementation of POSIX semaphores does not support
|
29
|
-
timeouts.
|
30
|
-
do support timeouts.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
process_shared overrides Ruby's `fork
|
36
|
-
copied from parent to child to emulate the POSIX
|
59
|
+
timeouts. But, the Mach layer in Mac OS X has its own semaphores that
|
60
|
+
do support timeouts. Thus, process_shared implements a moderate subset
|
61
|
+
of the Mach API, which is quite a bit different from POSIX. Namely,
|
62
|
+
semaphores created in one process are not available in child processes
|
63
|
+
created via `fork()`. Mach does provide the means to copy capabilities
|
64
|
+
between tasks (Mach equivalent to processes). In a giant hack, **on OS
|
65
|
+
X, `process_shared` overrides Ruby's `fork`** methods so that
|
66
|
+
semaphores are copied from parent to child to emulate the POSIX
|
67
|
+
behavior.
|
37
68
|
|
38
69
|
This is an incomplete work in progress.
|
39
70
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process_shared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Mahoney
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: ci_reporter_minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '1.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: flog
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -213,9 +213,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
213
|
version: '0'
|
214
214
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
215
|
requirements:
|
216
|
-
- - "
|
216
|
+
- - ">="
|
217
217
|
- !ruby/object:Gem::Version
|
218
|
-
version:
|
218
|
+
version: '0'
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
221
|
rubygems_version: 2.2.0
|
@@ -223,4 +223,3 @@ signing_key:
|
|
223
223
|
specification_version: 4
|
224
224
|
summary: process-shared synchronization primitives
|
225
225
|
test_files: []
|
226
|
-
has_rdoc: true
|