The key to preventing trouble involving shared storage is find some way to prohibit more than one process from reading and writing the shared data simultaneously. That part of the program where the shared memory is accessed is called the Critical Section. To avoid race conditions and flawed results, one must identify codes in Critical Sections in each thread. The characteristic properties of the code that form a Critical Section are
- Codes that reference one or more variables in a read-update-write fashion while any of those variables is possibly being altered by another thread.
- Codes that alter one or more variables that are possibly being referenced in read-updata-write fashion by another thread.
- Codes use a data structure while any part of it is possibly being altered by another thread.
- Codes
alter any part of a data structure while it is possibly in use by another
thread.
No comments:
Post a Comment