barrier-1.0.2/0000755000004100000410000000000013343502333013167 5ustar www-datawww-databarrier-1.0.2/LICENSE0000644000004100000410000000210013343502333014165 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) Aleksey Vereshchagin, 2015 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. barrier-1.0.2/barrier.gemspec0000644000004100000410000000205713343502333016166 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: barrier 1.0.2 ruby lib Gem::Specification.new do |s| s.name = "barrier".freeze s.version = "1.0.2" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Aleksey Vereshchagin".freeze] s.date = "2015-02-12" s.description = "A synchronization barrier enables multiple threads to wait until all threads have all reached a particular point of execution before any thread continues.".freeze s.email = "alexeyv.90@gmail.com".freeze s.files = ["LICENSE".freeze, "lib/barrier.rb".freeze] s.homepage = "http://rubygems.org/gems/barrier".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 1.8.6".freeze) s.rubygems_version = "2.5.2.1".freeze s.summary = "A barrier for threads synchronization".freeze end barrier-1.0.2/lib/0000755000004100000410000000000013343502333013735 5ustar www-datawww-databarrier-1.0.2/lib/barrier.rb0000644000004100000410000000220613343502333015710 0ustar www-datawww-datarequire 'thread' # A synchronization barrier enables multiple threads to wait until all threads # have all reached a particular point of execution before any thread # continues. class Barrier # Initialize new barrier. The _count_ argument specifies the number of threads # that must call #wait before any of them successfully return from the call. # The value specified by _count_ must be greater than zero. # # For example # b = Barrier.new(3) # 3.times do # Thread.new do # print 1 # b.wait # print 2 # end # end # sleep(1) # puts # produce # 111222 def initialize(count) @count_max = count @count = 1 @mutex = Mutex.new @lock = ConditionVariable.new end # The #wait function shall synchronize participating threads at the barrier. # The calling thread shall block until the required number of threads have # called #wait specifying the barrier. def wait @mutex.synchronize do if @count < @count_max @count += 1 @lock.wait(@mutex) else @count = 1 @lock.broadcast end end nil end end