From: Sean Russell Date: 2001-07-05T09:59:57+09:00 Subject: [ruby-talk:17260] Re: ruby community -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 03 July 2001 20:40, you wrote: > Well, Guy totally came to the rescue, he dissected a bad function and > explained to me that when something is said to not be "thread safe" it > means that you have made a system call that could block, and you need > to deal with that situation. The way to deal with such a situation is > something like this (if I understood correctly): I'd hate to confuse the issue, but thread-safedness affects more than just system calls. It affects any shared object accessed by two or more threads, whereby operations are not atomic and therefore prone to functional errors. The common, trivial, example is: class SomeClass attr_reader _items def initialize _items = [] end def do_something if _items.length > 0 # Danger, Will Robinson! item = _items.pop # Do something with item, expecting it to be non-nil end end end If you use this class in a threaded environment, it is possible that two threads could call do_something on the same object at (nearly) the same time, and that the scheduler could interrupt the code right after the length comparison. The second thread would execute, pop the stack, and when the first thread resumes, it would be in trouble. In any case, it isn't just system calls that have to be checked for thread-safedness, but any object which is being used by multiple threads. - --- SER Deutsch|Esperanto|Francais|Linux|Java|Dirigibles|GPG|Pegwit "Did you ever notice that while MS stands for Microsoft, it also stands for the dread disease Multiple Sclerosis? Well, why not? They're both slow, crippling and ultimately deadly." -- Monika McDole -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE7Q7wGP0KxygnleI8RAqbeAKCszUQa0I9Ts9aD7uP3M7rzy4hOrQCgvESu sSL4cXHNueh2RBD4NzGmGr4= =BTz5 -----END PGP SIGNATURE-----