asynchronous 1.0.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTU5ZGY2NjQ1ZjAwMDBkNDhmN2JhMjkwZjdjNjk4M2RiMWQxYTRmOQ==
4
+ OTNkMmY0MjUwZmI4OTNhYThjYzcwZmFmYTJjN2U4MjNjNzZmZDJmYg==
5
5
  data.tar.gz: !binary |-
6
- MDY5MjRjMjhjMzc2YmUxZWUzODFiMWY4NWNkYWFiM2RmZDdmNjg5MQ==
6
+ ODQ3ZDc0YTU1Yzc0N2VjYWFjYTgyMzBmODBmNDkwYjEzOWZlZmY0Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Mjg5MzZiN2I3NDM4Yzc2MmYwYzMyNzk3OGUxOWU3NjIwZTdiNjg2NDM0NGQx
10
- NGQ2MGE4NmFiYTgxNDM1OWVmMmQ5YjMwZjI5ODcxZTM2MTk0NWE5OTdiOWI1
11
- NTY2N2FhODI4N2JkOTljNDU1OTE5NGY0YTM4NWY3MTliNzIyNWQ=
9
+ OWQwOTg0MDVlZDVlMjQ2NTk4YjJjM2VhZDU2ZTZiMmI4OTAyZjhjYjk0N2Yy
10
+ NWNhM2RmNDcxMjVlMTJiMjNlNTU4Y2M0ZDBhZWU1OTE5OTVkNGZkNGVkOWRi
11
+ YWRkYzI5ZWE2OWE5MDVlNzNjYzBhMWRiYzQ5YzA3OTJlNTFkMTE=
12
12
  data.tar.gz: !binary |-
13
- ZjViMzZjODEwNTI2MzIxZjNlYjE0MDZkMTg0MzNiNzY1MTQ3MDYyNmI1MzJh
14
- ZTE3ODQxMWFjNjhlYmE3MWNjMDgwMmQ2NmQyOWNhNGJjOWVlOTY0ZTZhYjI4
15
- N2YzOTZiYzEzOWJhNTMyZDFlNmRiMDE3Y2JmYTkxZjU4ZmExZDM=
13
+ ZGZkZmI1MGEwNWExMTRmNTMyM2M1NTIxMDdiOTQ5NjRmMmFlNmYwZWMwOWMw
14
+ N2NmODk4ZTY5NTU5ZWYyZjFmMDIxZmMzODM1NWQ5M2Y0MDczMmJiNjE0ZThj
15
+ YjIyMjQ4NmE4OTY5OTc2MTAyMzI5YzIzYjc3ZjU2MDVlMTg2YjI=
data/Gemfile CHANGED
@@ -1,13 +1,2 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "rdoc", "~> 3.12"
11
- gem "bundler", "~> 1.0"
12
- gem "jeweler", "~> 1.8.7"
13
- end
2
+ gemspec
@@ -1,72 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ asynchronous (1.1.0.pre.pre)
5
+ process_shared
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
4
- activesupport (4.0.0)
5
- i18n (~> 0.6, >= 0.6.4)
6
- minitest (~> 4.2)
7
- multi_json (~> 1.3)
8
- thread_safe (~> 0.1)
9
- tzinfo (~> 0.3.37)
10
- addressable (2.3.5)
11
- atomic (1.1.14)
12
- builder (3.2.2)
13
- faraday (0.8.8)
14
- multipart-post (~> 1.2.0)
15
- git (1.2.6)
16
- github_api (0.10.1)
17
- addressable
18
- faraday (~> 0.8.1)
19
- hashie (>= 1.2)
20
- multi_json (~> 1.4)
21
- nokogiri (~> 1.5.2)
22
- oauth2
23
- hashie (2.0.5)
24
- highline (1.6.20)
25
- httpauth (0.2.0)
26
- i18n (0.6.5)
27
- jeweler (1.8.8)
28
- builder
29
- bundler (~> 1.0)
30
- git (>= 1.2.5)
31
- github_api (= 0.10.1)
32
- highline (>= 1.6.15)
33
- nokogiri (= 1.5.10)
34
- rake
35
- rdoc
36
- json (1.8.1)
37
- jwt (0.1.8)
38
- multi_json (>= 1.5)
39
- minitest (4.7.5)
40
- multi_json (1.8.2)
41
- multi_xml (0.5.5)
42
- multipart-post (1.2.0)
43
- nokogiri (1.5.10)
44
- oauth2 (0.9.2)
45
- faraday (~> 0.8)
46
- httpauth (~> 0.2)
47
- jwt (~> 0.1.4)
48
- multi_json (~> 1.0)
49
- multi_xml (~> 0.5)
50
- rack (~> 1.2)
51
- rack (1.5.2)
52
- rake (10.1.0)
53
- rdoc (3.12.2)
54
- json (~> 1.4)
55
- shoulda (3.5.0)
56
- shoulda-context (~> 1.0, >= 1.0.1)
57
- shoulda-matchers (>= 1.4.1, < 3.0)
58
- shoulda-context (1.1.5)
59
- shoulda-matchers (2.4.0)
60
- activesupport (>= 3.0.0)
61
- thread_safe (0.1.3)
62
- atomic
63
- tzinfo (0.3.38)
10
+ ffi (1.9.3)
11
+ process_shared (0.2.0)
12
+ ffi (~> 1.0)
64
13
 
65
14
  PLATFORMS
66
15
  ruby
67
16
 
68
17
  DEPENDENCIES
69
- bundler (~> 1.0)
70
- jeweler (~> 1.8.7)
71
- rdoc (~> 3.12)
72
- shoulda
18
+ asynchronous!
data/README.md CHANGED
@@ -8,7 +8,7 @@ real async patterns in ruby
8
8
  Well it is achived in Ruby really simple, and elegant way.
9
9
 
10
10
 
11
- ## Quoting Sun's Multithreaded Programming Guide:
11
+ ### Quoting Sun's Multithreaded Programming Guide:
12
12
 
13
13
  Parallelism:
14
14
  - A condition that arises when at least two threads are executing simultaneously.
@@ -17,7 +17,7 @@ Concurrency:
17
17
  - A condition that exists when at least two threads are making progress.
18
18
  - A more generalized form of parallelism that can include time-slicing as a form of virtual parallelism
19
19
 
20
- ### for short:
20
+ #### for short:
21
21
 
22
22
  Concurrency is when two tasks can start, run, and complete in overlapping time periods.
23
23
  It doesn't necessarily mean they'll ever both be running at the same instant.
@@ -27,7 +27,7 @@ Parallelism is when tasks literally run at the same time.
27
27
  Eg. on a multicore processor.
28
28
 
29
29
 
30
- ## OS managed thread (Native Threads)
30
+ ### OS managed thread (Native Threads)
31
31
 
32
32
  copy on write memory share,
33
33
  so you cant change anything in the mother process
@@ -73,33 +73,56 @@ calculation= async { sleep 3; 4 * 3 }
73
73
  calculation.value
74
74
 
75
75
  ```
76
- # Examples
77
76
 
78
- the "async patterns" will let you see how easy to use threads
79
- for multiprocessing so you can give multiple task to do and
80
- until you need they value, let the process run in the background
77
+ ### Shared Memory
81
78
 
82
- ## LICENSE
79
+ By default the last value will be returned (OS) in IO.pipe,
80
+ but when you need something else, there is the shared_memory!
83
81
 
84
- (The MIT License)
82
+ Shared memory is good when you want make a ruby worked on native OS thread ,
83
+ but need to update data back at the mother process.
85
84
 
86
- Copyright (c) 2009-2013 Adam Luzsi <adamluzsi@gmail.com>
85
+ the usecase is simple like that:
86
+ ```ruby
87
+
88
+ SharedMemory.anything_you_want_use_as_variable_name= {:some=>:object}
89
+ SharedMemory.anything_you_want_use_as_variable_name #> {:some=>:object}
90
+
91
+ ```
92
+
93
+ by default i set the memory allocation to 16Mb because it common usecase to me (MongoDB),
94
+ but feel free to change!:
95
+ ```ruby
96
+
97
+ Asynchronous::Allocation.memory_allocation_size= 1024 #INT!
98
+
99
+ ```
100
+
101
+ ## Example
87
102
 
88
- Permission is hereby granted, free of charge, to any person obtaining
89
- a copy of this software and associated documentation files (the
90
- 'Software'), to deal in the Software without restriction, including
91
- without limitation the rights to use, copy, modify, merge, publish,
92
- distribute, sublicense, and/or sell copies of the Software, and to
93
- permit persons to whom the Software is furnished to do so, subject to
94
- the following conditions:
103
+ ```ruby
104
+
105
+ # you can use simple :p or :parallelism as nametag
106
+ # remember :parallelism is all about real OS thread case, so
107
+ # you CANT modify the objects in memory only in sharedmemories,
108
+ # the normal variables will only be copy on write modify
109
+ # This is ideal for big operations where you need do a big process
110
+ # w/o the fear of the Garbage collector slowness or the GIL lock
111
+ # when you need to update objects in the memory use SharedMemory
112
+ #
113
+ # Remember! if the hardware only got 1 cpu, it will be like a harder
114
+ # to use concurrency with an expensive memory allocation
115
+ calculation = async :OS do
116
+
117
+ sleep 4
118
+ 4 * 5
95
119
 
96
- The above copyright notice and this permission notice shall be
97
- included in all copies or substantial portions of the Software.
120
+ end
121
+
122
+ calculation.value += 1
123
+
124
+ puts calculation.value
125
+
126
+ ```
98
127
 
99
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
100
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
101
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
102
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
103
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
104
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
105
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
128
+ there are other examples that you can check in the exampels folder
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 2.0.0
@@ -12,17 +12,13 @@ Gem::Specification.new do |spec|
12
12
  spec.description = %q{DSL for for dead simple to use asynchronous patterns in both VM managed and OS managed way (Concurrency and Parallelism) }
13
13
  spec.summary = %q{Simple Async Based on standard CRuby}
14
14
  spec.homepage = "https://github.com/adamluzsi/asynchronous"
15
- spec.license = "MIT"
15
+ #spec.license = "MIT"
16
16
 
17
17
  spec.files = SpecFiles
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- ##=======Runtime-ENV================##
23
- #spec.add_runtime_dependency "asdf", ['~>4.1.3']
24
-
25
- ##=======Development-ENV============##
26
- #spec.add_development_dependency "asdf",['~>4.1.3']
22
+ spec.add_dependency "process_shared"
27
23
 
28
24
  end
File without changes
@@ -1,4 +1,4 @@
1
- require 'async'
1
+ require_relative "../lib/asynchronous"
2
2
 
3
3
  async1= async :OS do
4
4
 
@@ -34,13 +34,13 @@ puts calculation.value
34
34
 
35
35
  #>--------------------------------------------------
36
36
  # now let's see the Parallelism
37
- # you can use simple :p also instead of :parallelism
37
+ # you can use simple :p or :parallelism as nametag
38
38
  # remember :parallelism is all about real OS thread case, so
39
- # you CANT modify the objects in memory only copy on write modify
39
+ # you CANT modify the objects in memory only in sharedmemories,
40
+ # the normal variables will only be copy on write modify
40
41
  # This is ideal for big operations where you need do a big process
41
- # and only get the return value so you can do big works without the fear of the
42
- # Garbage collector slowness or the GIL lock
43
- # when you need to update objects in the memory use :concurrency
42
+ # w/o the fear of the Garbage collector slowness or the GIL lock
43
+ # when you need to update objects in the memory use SharedMemory
44
44
  calculation = async :parallelism do
45
45
 
46
46
  sleep 4
@@ -0,0 +1,19 @@
1
+ require_relative "../lib/asynchronous"
2
+
3
+ SharedMemory.test_value= 0
4
+ async :OS do
5
+
6
+ loop do
7
+ SharedMemory.test_value += 1
8
+ sleep 3
9
+ end
10
+
11
+ end
12
+
13
+ loop do
14
+ if SharedMemory.test_value >= 10
15
+ Process.exit
16
+ end
17
+ puts SharedMemory.test_value
18
+ sleep 1
19
+ end
@@ -1,9 +1,11 @@
1
1
  #encoding: UTF-8
2
2
  module Asynchronous
3
3
 
4
+ require 'process_shared'
4
5
  require File.join(File.dirname(__FILE__),"asynchronous","clean_class")
5
6
  require File.join(File.dirname(__FILE__),"asynchronous","concurrency")
6
7
  require File.join(File.dirname(__FILE__),"asynchronous","parallelism")
8
+ require File.join(File.dirname(__FILE__),"asynchronous","shared_memory")
7
9
  require File.join(File.dirname(__FILE__),"asynchronous","kernel")
8
10
 
9
11
  end
@@ -0,0 +1,138 @@
1
+ require 'process_shared'
2
+ require_relative "clean_class"
3
+ module Asynchronous
4
+
5
+
6
+ module Allocation
7
+
8
+ class << self
9
+ attr_accessor :memory_allocation_size
10
+ end
11
+
12
+ self.memory_allocation_size= 16384
13
+
14
+ def self.mutex
15
+ @@mutex
16
+ end
17
+
18
+ @@mutex = ProcessShared::Mutex.new
19
+
20
+ end
21
+
22
+
23
+ class SharedMemory < CleanClass
24
+ class << self
25
+ def method_missing(method, *args)
26
+
27
+ ::Asynchronous::Allocation.mutex.synchronize do
28
+ if method.to_s.include?('=')
29
+ begin
30
+ self.class_variable_get("@@#{method.to_s.sub('=','')}").write_object(args[0])
31
+ rescue ::NameError
32
+ self.class_variable_set(
33
+ "@@#{method.to_s.sub('=','')}",
34
+ ::ProcessShared::SharedMemory.new( ::Asynchronous::Allocation.memory_allocation_size )
35
+ )
36
+ self.class_variable_get("@@#{method.to_s.sub('=','')}").write_object(args[0])
37
+ end
38
+ else
39
+ begin
40
+ self.class_variable_get("@@#{method.to_s}").read_object
41
+ rescue ::NameError
42
+ return nil
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ end
53
+
54
+ SharedMemory ||= Asynchronous::SharedMemory
55
+
56
+
57
+
58
+ =begin
59
+
60
+
61
+ # The C void type; only useful for function return types
62
+ :void => Type::VOID,
63
+
64
+ # C boolean type
65
+ :bool => Type::BOOL,
66
+
67
+ # C nul-terminated string
68
+ :string => Type::STRING,
69
+
70
+ # C signed char
71
+ :char => Type::CHAR,
72
+ # C unsigned char
73
+ :uchar => Type::UCHAR,
74
+
75
+ # C signed short
76
+ :short => Type::SHORT,
77
+ # C unsigned short
78
+ :ushort => Type::USHORT,
79
+
80
+ # C signed int
81
+ :int => Type::INT,
82
+ # C unsigned int
83
+ :uint => Type::UINT,
84
+
85
+ # C signed long
86
+ :long => Type::LONG,
87
+
88
+ # C unsigned long
89
+ :ulong => Type::ULONG,
90
+
91
+ # C signed long long integer
92
+ :long_long => Type::LONG_LONG,
93
+
94
+ # C unsigned long long integer
95
+ :ulong_long => Type::ULONG_LONG,
96
+
97
+ # C single precision float
98
+ :float => Type::FLOAT,
99
+
100
+ # C double precision float
101
+ :double => Type::DOUBLE,
102
+
103
+ # C long double
104
+ :long_double => Type::LONGDOUBLE,
105
+
106
+ # Native memory address
107
+ :pointer => Type::POINTER,
108
+
109
+ # 8 bit signed integer
110
+ :int8 => Type::INT8,
111
+ # 8 bit unsigned integer
112
+ :uint8 => Type::UINT8,
113
+
114
+ # 16 bit signed integer
115
+ :int16 => Type::INT16,
116
+ # 16 bit unsigned integer
117
+ :uint16 => Type::UINT16,
118
+
119
+ # 32 bit signed integer
120
+ :int32 => Type::INT32,
121
+ # 32 bit unsigned integer
122
+ :uint32 => Type::UINT32,
123
+
124
+ # 64 bit signed integer
125
+ :int64 => Type::INT64,
126
+ # 64 bit unsigned integer
127
+ :uint64 => Type::UINT64,
128
+
129
+ :buffer_in => Type::BUFFER_IN,
130
+ :buffer_out => Type::BUFFER_OUT,
131
+ :buffer_inout => Type::BUFFER_INOUT,
132
+
133
+ # Used in function prototypes to indicate the arguments are variadic
134
+ :varargs => Type::VARARGS,
135
+
136
+
137
+ =end
138
+
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchronous
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: process_shared
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'
13
27
  description: ! 'DSL for for dead simple to use asynchronous patterns in both VM managed
14
28
  and OS managed way (Concurrency and Parallelism) '
15
29
  email:
@@ -20,26 +34,25 @@ extra_rdoc_files: []
20
34
  files:
21
35
  - Gemfile
22
36
  - Gemfile.lock
23
- - LICENSE
24
- - LICENSE.txt
25
37
  - README.md
26
38
  - Rakefile
27
39
  - VERSION
28
40
  - asynchronous.gemspec
41
+ - dump/async.rb
29
42
  - examples/array_of_value_with_native_threads.rb
30
43
  - examples/async_patterns.rb
31
44
  - examples/no_zombie_test.rb
45
+ - examples/shared_memory.rb
32
46
  - files.rb
33
- - lib/async.rb
34
47
  - lib/asynchronous.rb
35
48
  - lib/asynchronous/clean_class.rb
36
49
  - lib/asynchronous/concurrency.rb
37
50
  - lib/asynchronous/kernel.rb
38
51
  - lib/asynchronous/parallelism.rb
52
+ - lib/asynchronous/shared_memory.rb
39
53
  - test/test.rb
40
54
  homepage: https://github.com/adamluzsi/asynchronous
41
- licenses:
42
- - MIT
55
+ licenses: []
43
56
  metadata: {}
44
57
  post_install_message:
45
58
  rdoc_options: []
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 Adam Luzsi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,20 +0,0 @@
1
- Copyright (c) 2013 Adam Luzsi
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.