[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03738] Re: Multithreaded/Embedded Ruby?

From: David Bolen <db3l@...>
Date: 2000-07-01 00:51:02 UTC
List: ruby-talk #3738
"R. Hotaka" <hotaka@media.teu.ac.jp> writes:

> This is from Hotaka@TUT
> 
> If a thread can read (but not write) the value of a variable defined
> in (or possesed by) another thread, can we say that situation
> "thread safe"?

One thing to be cautious of is that thread-safety is often not just a
read-only versus read-write issue.  Data access in general can be
risky depending on how that access is performed and how thread
scheduling takes place.

For example, in a pre-emptive threading system, if you have a variable
that requires several machine instructions to fetch from memory and/or
decode, then it is possible for one thread to be in the process of
changing the variable while another is reading it (or vice versa), and
for the reading thread to obtain a corrupted version of the variable.
Even if the reading thread accesses the variable as a read-only
object, without proper exclusion protection on the access, it is still
possible to not be a thread-safe system.

Such corruption can occur at higher levels as well - let's say you
have an object that you can request state from and that state consists
of several pieces of information.  Even if you are treating the object
as read-only, if someone else can change that state, and interrupts
your thread that is querying it, you may obtain state with a mixture
of information from before and after the change.  That is, unless the
object itself ensures the integrity of any state changes and access to
the state information.

In general, to really consider a system thread-safe, it must be a
system that was designed to expect multiple accesses to common data
and resources, and thus to always protect any accesses to such
resources with some protection (semaphores, critical sections,
etc...).  The resources being protected may be individual data
elements, or they may be higher level structures which must be
self-consistent at all points in time.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l@fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/

In This Thread