Prev | Current Page 273 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"


On the other side, imagine the worker thread taking tasks off the list. Again, removing a task from the list
will require multiple machine instructions. The worker thread will also be checking to see if the list is empty,
for there may be no work to do. In that case, the worker thread will wait until some task is added to the list by
the server thread.
Since an interrupt can occur between any two machine instructions, and since the operating system may
choose to execute any ready thread at any moment, it is possible that the server thread will be interrupted as it
adds a task to the list, and that the worker thread will be scheduled to execute next. Without some control to
insure that items are added to and removed from the list at appropriate times and as whole items, it??™s possible
that the coordination will fail.
For instance, suppose the server thread finds the address of the last element of the list and then is interrupted.
After the OS services the interrupt, the OS schedules the worker thread, which removes a task from the list and
completes processing. In fact, the worker may continue to execute and remove several tasks from the list before
the OS intervenes to schedule another thread. When the server thread eventually regains the CPU, it will continue
from the point it was interrupted, and store a reference to a new task in the location it previously computed.


Pages:
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
wycieczki do Norwegii skarpetki narciarskie męskie zarządzanie sprzedażą online loan for bad credit remont warszawa