-
Book Overview & Buying
-
Table Of Contents
Polished Ruby Programming - Second Edition
By :
Let's say you are dealing with an application where a process-based approach to concurrency will not work, such as when your application needs to pass ractor-shareable but unmarshallable objects between tasks. Let's say the application also uses a C extension that does not have a pure-Ruby or Java-based equivalent, so that JRuby could not be considered. In this case, using ractors may be the best way to improve performance, as it is the only way to allow for parallel execution of Ruby code in CRuby.
Let's say the application is using an object that allows thread-safe access to a hash. Like most Ruby applications, this application was not written with ractors in mind, and currently uses mutable instance variables for caching. The object exposes a [] method for reading from the hash, and a []= method for writing to the hash, wrapping all access to the hash in a mutex:
class ThreadIsolatedHash
attr_reader :data
def initialize
@data =...
Change the font size
Change margin width
Change background colour