![]() ![]() Code that is safe from concurrency on symmetrical multiprocessing machines is SMP-safe. “Code that is safe from concurrent access from an interrupt handler is said to be interrupt-safe. Two or more processors can execute code at the same time. When a task sleeps it will invoke the scheduler, resulting in running a new process. Sleeping and synchronization with user space.The kernel can raise or schedule a softirq or tasklet at almost any time. An interrupt can occur at almost any time. The kernel has several sources of concurrency: For example, locks are implemented on x86 with an instruction called copy and exchange. Locks can be implemented with atomic instructions that can test the value of an integer and set it to a new value only if it’s zero. Other locks work by putting the process to sleep until the lock becomes available. Some lock variants work by busy waiting: looping continuously until a lock becomes available. They are a programming construct that must be followed by every other program in order for them to provide atomic access to critical regions. When it leaves the room, it unlocks the door so that other processes can enter the critical region. The process is then free to execute instructions without being interrupted. When a process enters a critical region, it locks the door behind it. Linux includes several different locking mechanisms. LockingĪ lock is a way to prevent multiple threads of execution from entering a critical region at the same time. But sometimes the critical region contains many instructions that don’t have an atomic equivalent. Most processors provide an instruction to atomically read, increment, and write-back. The solution is for the set of increment instructions to be performed atomically as a single instruction. This would result in i being set to 8, rather than 7. Ĭonsider a shared resource with a single critical region: a global integer with an operation that increments it: Ensuring that race conditions don’t occur is called synchronization. Race conditions are very difficult to debug because they will not reproduce deterministically. Two threads of execution executing simultaneously in a critical region is a bug, known as a race condition. To prevent concurrent access in a critical region, the program code must execute atomically, where atomic operations are operations that complete without interruption. It’s usually unsafe for multiple threads of execution to access the same resources concurrently. “Code paths that access and manipulate shared data are called critical regions”. This section is about the problems of concurrency, and the tools for kernel synchronization. The scheduler can preempt kernel code at almost any point. Linux has symmetrical multiprocessing support: kernel code can simultaneously run on two or more processors. Protecting shared resources in Linux can be tough. This is because other threads of execution might modify data at the same time, resulting in problems like the data being overwritten by one thread, or data being accessed in an inconsistent state. Shared resources in the kernel require protection from concurrent access. This site uses Just the Docs, a documentation theme for Jekyll. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |