Skip to content

Instantly share code, notes, and snippets.

@tomotaka
Created July 13, 2011 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomotaka/1079628 to your computer and use it in GitHub Desktop.
Save tomotaka/1079628 to your computer and use it in GitHub Desktop.
cyclic iterator for multithread
class SyncCyclicIterator
def initialize(ary)
@ary = ary
@mtx = Mutex.new
@idx = 0
end
def next
ret = nil
@mtx.synchronize do
ret = @ary[@idx]
@idx += 1
@idx = 0 if @idx == @ary.size
end
return ret
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment