JezK
Edit File: cdesc-Semaphore.ri
U:RDoc::NormalClass[iI"Semaphore:EFI"Concurrent::Semaphore;FI"SemaphoreImplementation;To:RDoc::Markup::Document:@parts[o;;[ o:RDoc::Markup::Paragraph;[I"@!macro [attach] semaphore;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim;[I"HA counting semaphore. Conceptually, a semaphore maintains a set of ;TI"Dpermits. Each {#acquire} blocks if necessary until a permit is ;TI"Navailable, and then takes it. Each {#release} adds a permit, potentially ;TI"$releasing a blocking acquirer. ;TI"LHowever, no actual permit objects are used; the Semaphore just keeps a ;TI"9count of the number available and acts accordingly. ;T:@format0o; ;[I""@!macro semaphore_public_api ;TI" @example;To;;[#I".semaphore = Concurrent::Semaphore.new(2) ;TI" ;TI"t1 = Thread.new do ;TI" semaphore.acquire ;TI"* puts "Thread 1 acquired semaphore" ;TI" end ;TI" ;TI"t2 = Thread.new do ;TI" semaphore.acquire ;TI"* puts "Thread 2 acquired semaphore" ;TI" end ;TI" ;TI"t3 = Thread.new do ;TI" semaphore.acquire ;TI"* puts "Thread 3 acquired semaphore" ;TI" end ;TI" ;TI"t4 = Thread.new do ;TI" sleep(2) ;TI"+ puts "Thread 4 releasing semaphore" ;TI" semaphore.release ;TI" end ;TI" ;TI"#[t1, t2, t3, t4].each(&:join) ;TI" ;TI"# prints: ;TI"## Thread 3 acquired semaphore ;TI"## Thread 2 acquired semaphore ;TI"$# Thread 4 releasing semaphore ;TI""# Thread 1 acquired semaphore;T;0: @fileI"'lib/concurrent/atomic/semaphore.rb;T:0@omit_headings_from_table_of_contents_below0; 0;0[ [ [ [[I" class;T[[:public[ [:protected[ [:private[ [I" instance;T[[;[ [;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ; 0;0[@>I"Concurrent;FcRDoc::NormalModule