Task preemption happens automatically and unavoidably; very few processes escape preemption.
What you might not realize, however, is that a process can voluntarily yield its quantum of CPU
time. That is, while a process cannot request additional CPU time, it can voluntarily give it up. The
implication of this for a developer is that you can delay executing certain blocks of code if they are
either non-critical or rely on input from other processes that are still running. The function that
makes this possible is named sched_yield().
Multitasking, while a boon for computer users, poses (at least) three potential problems for programmers:
deadlocks, livelocks, and races:
Deadlocks??”A deadlock occurs when two or more processes are unable to proceed
because each is waiting for one of the others to do something. Deadlocks can happen in
several ways. For example, suppose an e-mail client is communicating with a mail server,
755
Programming Environments and Interfaces 28
waiting for the server to send a message. A deadlock occurs if the mail server is waiting
for input from the e-mail client before sending the message. This type of deadlock is
sometimes referred to as a deadly embrace. A starvation deadlock occurs when one or
more low-priority processes never get time on the CPU because they are crowded out by
higher-priority processes.
Pages:
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376