JezK
Edit File: cdesc-AbstractExchanger.ri
U:RDoc::NormalClass[iI"AbstractExchanger:EFI""Concurrent::AbstractExchanger;FI"Synchronization::Object;To:RDoc::Markup::Document:@parts[o;;[ o:RDoc::Markup::Paragraph;[I"@!macro [attach] exchanger;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim;[I"PA synchronization point at which threads can pair and swap elements within ;TI"Npairs. Each thread presents some object on entry to the exchange method, ;TI"Qmatches with a partner thread, and receives its partner's object on return. ;TI" ;TI"-@!macro thread_safe_variable_comparison ;TI" ;TI"KThis implementation is very simple, using only a single slot for each ;TI"Lexchanger (unlike more advanced implementations which use an "arena"). ;TI"NThis approach will work perfectly fine when there are only a few threads ;TI"Qaccessing a single `Exchanger`. Beyond a handful of threads the performance ;TI"Rwill degrade rapidly due to contention on the single slot, but the algorithm ;TI"will remain correct. ;TI" ;TI"v@see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Exchanger.html java.util.concurrent.Exchanger ;TI" ;TI"@!macro edge_warning ;TI" ;TI"@example ;TI" ;TI"- exchanger = Concurrent::Exchanger.new ;TI" ;TI" threads = [ ;TI"Y Thread.new { puts "first: " << exchanger.exchange('foo', 1) }, #=> "first: bar" ;TI"Z Thread.new { puts "second: " << exchanger.exchange('bar', 1) } #=> "second: foo" ;TI" ] ;TI"% threads.each {|t| t.join(2) } ;T:@format0o; ;[I"@!visibility private;T: @fileI" lib/concurrent/exchanger.rb;T:0@omit_headings_from_table_of_contents_below0; 0;0[ [U:RDoc::Constant[i I"CANCEL;FI"*Concurrent::AbstractExchanger::CANCEL;F00o;;[o; ;[I"@!visibility private;T; @1;0@1@cRDoc::NormalClass0[ [[I" class;T[[:public[[I"new;TI" lib/concurrent/exchanger.rb;T[:protected[ [:private[ [I" instance;T[[;[[I" exchange;F@G[I"exchange!;F@G[I"try_exchange;F@G[;[ [;[[I"do_exchange;F@G[ [U:RDoc::Context::Section[i 0o;;[ ; 0;0[@1I"Concurrent;FcRDoc::NormalModule