TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Craig Swanson
from: Phil Crown
date: 1996-01-28 00:24:10
subject: thread safe

-=> Quoting Craig Swanson to Phil Crown <=- 

 CS> Making code thread-safe usually involves the following:

 CS> 1) Avoid global variables

 CS> 2) Use local (i.e., auto or allocated on the stack) variables

Does this mean making sure that the compiler/optimizer doesn't register any
local variables?  Someone mentioned a bug in Borland that it was ignoring
the command not to register local variables or something like that.

 CS> 3) Protect resources that are not strictly local using mutex
 CS> semaphores or handle them using some other scheme such as atomic
 CS> bit test-and-set, inc/dec, and exchange operations

 CS> Making code SMP-safe takes it one step further as you must then
 CS> consider that some practices that would be safe on a single CPU system
 CS> will not be safe on a multiple CPU system.  For instance, a simple
 CS> Intel x86 INC instruction used to update a counter being handled by
 CS> multiple threads would need to have a LOCK prefix before it to make it
 CS> SMP-safe.

I know how to use mutex semaphores and I doubt anything I write will ever
run on an SMP system.

Thanks!

Phil
Fido:  1:124/8014.1 | Internet:  phil.crown{at}bluecafe.com


--- Blue Wave/OS2 v2.22b
* Origin: The Wild! Blue BBS -=* Home of The Blue Wave *=- (1:2240/176)
SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 2240/176 234/100 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.