Ruby Threads
Today, I encountered my first Ruby gripe.
Variables mapped from collection passed into Ruby threads are not independent of one another. If one thread changes the passed variable, all of other threads share the new variable.
Let’s suppose I have an Array of items = ["item 1", "item 2", "item 3"]
Here’s some code that takes each item in the array and does some processing on it, printing out “finished!” statements after each element is processed.
items.map{|item| Thread.new(item){ #process with variable execution time goes here puts "#{item} finished!" }}
Let’s suppose the map task associated with “item 3″ starts last and ends first. Then the output could look like this:
item 3 finished!item 3 finished!item 3 finished!
The explanation for this peculiar behavior is detailed in Ruby Central’s Pragmatic Programmer’s Guide:
“A thread shares all global, instance, and local variables that are in existence at the time the thread starts.”



I’ve also begun using threads. I found that this is one of the major differences between threads and processes. It is not possible to share variables between processes. Since I had a need to share some variables between two processes, I switched to using threads.
I guess this behavior can be considered a benefit or drawback, depending on your expectations.
The Fastest iPhone Ever. The first thing you’ll notice about iPhone 3G S is how quickly you can launch applications. Web pages render in a fraction of the time, and you can view email attachments faster. Improved performance and updated 3D graphics deliver an incredible gaming experience, too. In fact, everything you do on iPhone 3G S is up to 2x faster and more responsive than iPhone 3G.
NB:This phone is unlocked and can be used with any SIM card. No activation required
Product Includes
Apple iPhone 3GS 32GB Unlocked
Apple Earphones with Remote and Mic
Dock Connector to USB Cable
USB Power Adapter
Documentation
SIM eject tool
Shipment will be made through FedEx Courier service within 24 hours and your order will be shipped out once payment is confirmed and you will be given a tracking number for you to track and trace your order online before it arrive your doorstep.
For any further information or to place an order please contact:
Contact Name:Nicolas Rabian
Tel:
E-mail: colenzo01@live.com