![]() But, can operation P decrement a semaphore value to a negative one? If so, does it mean operation V has to increment the semaphore to a positive value in order to give the process a permit? If the Process Sporadic Server option is supported, and the scheduling policy is SCHED_SPORADIC, the semantics are as per SCHED_FIFO above.I'm confused about how operations P & V work in semaphores(particulary in Java if there is a difference).Īs far as I know, operation P decrements the value of a semaphore, if the new value is <0 then the process is blocked, and operation V does the opposite. If the Process Scheduling option is not defined, the choice of a thread to unblock is unspecified. In the case of the schedulers SCHED_FIFO and SCHED_RR, the highest priority waiting thread shall be unblocked, and if there is more than one highest priority thread blocked waiting for the semaphore, then the highest priority thread that has been waiting the longest shall be unblocked. ![]() If the Process Scheduling option is supported, the thread to be unblocked shall be chosen in a manner appropriate to the scheduling policies and parameters in effect for the blocked threads. If the value of the semaphore resulting from this operation is zero, then one of the threads blocked waiting for the semaphore shall be allowed to return successfully from its call to sem_wait(). If the semaphore value resulting from this operation is positive, then no threads were blocked waiting for the semaphore to become unlocked the semaphore value is simply incremented. Basically, the OS wants to find the process that it's going to be able to be done with ASAP, so it can get back to sipping its tea and running your malware.Īccording to the IEEE standards, the behavior of POSIX semaphores: I/O-bound processes are likely to continue to be I/O-bound, which means that chances are they are going to switch off the CPU shortly while waiting for other resources. The theory is that new processes might be short-lived (if it's been around for five hours already, odds are it won't be finishing up in the next 1ms) so we might as well get them over with. In many OSes, priority is given to I/O-bound processes that haven't been around for very long. ![]() Then, the OS will switch in some totally unrelated process to run for a fraction of a second (probably Firefox or something), then go off and handle some network traffic, get itself a cup of tea, and, finally, when it gets around to it, pick whichever of your other threads it feels like, based on something like whether it feels based on past history that the particular thread is more CPU or I/O-bound. Most likely, your current thread (the one that called sem_post()) will continue running for a while, until it either starts waiting for user input, blocks on another semaphore, or runs out of its os-allotted time slice. It might be the thread that has been off the CPU for the longest, or the one that has been assigned the highest "priority", or the one that has historically had certain resource-usage statistics, or whatever. Nobody makes any guarantee of ordering it depends on your OS's scheduling strategy. The next thread to unblock on it's sem_wait() will be whatever thread the OS decides is the next one to context switch into.
0 Comments
Leave a Reply. |