What does it mean by code holding semaphore can be preempted
up vote
0
down vote
favorite
I was going through the Robert Love Book and was bit confused about this line. What does it mean by code holding semaphore can be preempted?
If an interrupt occurs accessing the same variable which the user-space application has while it is executing the code in critical section then the user-space application can be preempted?
If my above understanding is true then there is no other alternative than spin-locks to disable an interrupt whenever an user-space application is in critical section?
So what is the use of semaphore in the context of OS? Interrupts might occur anytime when the user application is in critical section and in-order to avoid interrupt intervention we need to use spin-locks all the time.
linux operating-system synchronization semaphore spinlock
add a comment |
up vote
0
down vote
favorite
I was going through the Robert Love Book and was bit confused about this line. What does it mean by code holding semaphore can be preempted?
If an interrupt occurs accessing the same variable which the user-space application has while it is executing the code in critical section then the user-space application can be preempted?
If my above understanding is true then there is no other alternative than spin-locks to disable an interrupt whenever an user-space application is in critical section?
So what is the use of semaphore in the context of OS? Interrupts might occur anytime when the user application is in critical section and in-order to avoid interrupt intervention we need to use spin-locks all the time.
linux operating-system synchronization semaphore spinlock
The problem with your question is that we do not know the context. What kind of semaphore? It is possible for a kernel to implement a semaphore so that the process holding it cannot be preempted. Or it a semaphore could be implement so that the process holding it could not be preempted.
– user3344003
Nov 2 at 22:32
Yes, but according to my understanding we can't implement a semaphore which cannot be preempted right when the interrupt occurs?
– Smita
Nov 2 at 22:59
You could block preemption as part of grabbing the semaphore. That's not normal but it could be done.
– user3344003
Nov 3 at 0:21
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I was going through the Robert Love Book and was bit confused about this line. What does it mean by code holding semaphore can be preempted?
If an interrupt occurs accessing the same variable which the user-space application has while it is executing the code in critical section then the user-space application can be preempted?
If my above understanding is true then there is no other alternative than spin-locks to disable an interrupt whenever an user-space application is in critical section?
So what is the use of semaphore in the context of OS? Interrupts might occur anytime when the user application is in critical section and in-order to avoid interrupt intervention we need to use spin-locks all the time.
linux operating-system synchronization semaphore spinlock
I was going through the Robert Love Book and was bit confused about this line. What does it mean by code holding semaphore can be preempted?
If an interrupt occurs accessing the same variable which the user-space application has while it is executing the code in critical section then the user-space application can be preempted?
If my above understanding is true then there is no other alternative than spin-locks to disable an interrupt whenever an user-space application is in critical section?
So what is the use of semaphore in the context of OS? Interrupts might occur anytime when the user application is in critical section and in-order to avoid interrupt intervention we need to use spin-locks all the time.
linux operating-system synchronization semaphore spinlock
linux operating-system synchronization semaphore spinlock
asked Nov 2 at 22:04
Smita
336
336
The problem with your question is that we do not know the context. What kind of semaphore? It is possible for a kernel to implement a semaphore so that the process holding it cannot be preempted. Or it a semaphore could be implement so that the process holding it could not be preempted.
– user3344003
Nov 2 at 22:32
Yes, but according to my understanding we can't implement a semaphore which cannot be preempted right when the interrupt occurs?
– Smita
Nov 2 at 22:59
You could block preemption as part of grabbing the semaphore. That's not normal but it could be done.
– user3344003
Nov 3 at 0:21
add a comment |
The problem with your question is that we do not know the context. What kind of semaphore? It is possible for a kernel to implement a semaphore so that the process holding it cannot be preempted. Or it a semaphore could be implement so that the process holding it could not be preempted.
– user3344003
Nov 2 at 22:32
Yes, but according to my understanding we can't implement a semaphore which cannot be preempted right when the interrupt occurs?
– Smita
Nov 2 at 22:59
You could block preemption as part of grabbing the semaphore. That's not normal but it could be done.
– user3344003
Nov 3 at 0:21
The problem with your question is that we do not know the context. What kind of semaphore? It is possible for a kernel to implement a semaphore so that the process holding it cannot be preempted. Or it a semaphore could be implement so that the process holding it could not be preempted.
– user3344003
Nov 2 at 22:32
The problem with your question is that we do not know the context. What kind of semaphore? It is possible for a kernel to implement a semaphore so that the process holding it cannot be preempted. Or it a semaphore could be implement so that the process holding it could not be preempted.
– user3344003
Nov 2 at 22:32
Yes, but according to my understanding we can't implement a semaphore which cannot be preempted right when the interrupt occurs?
– Smita
Nov 2 at 22:59
Yes, but according to my understanding we can't implement a semaphore which cannot be preempted right when the interrupt occurs?
– Smita
Nov 2 at 22:59
You could block preemption as part of grabbing the semaphore. That's not normal but it could be done.
– user3344003
Nov 3 at 0:21
You could block preemption as part of grabbing the semaphore. That's not normal but it could be done.
– user3344003
Nov 3 at 0:21
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
What does it mean by code holding semaphore can be preempted?
It means that a process that is currently running in its critical section holding some lock for the purpose of synchronization can be preempted. Ideally interrupts have the highest
priority, so unless you disable the interrupt on that processor core, the running process
can be preempted and that might happen while the process is in its critical section.
While there are multiple spin_lock_XXX apis to disable interrupts, you might want to use
the spin_lock_irqsave as it saves the interrupt flags on that core and restores them while releasing the lock.
New contributor
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
What does it mean by code holding semaphore can be preempted?
It means that a process that is currently running in its critical section holding some lock for the purpose of synchronization can be preempted. Ideally interrupts have the highest
priority, so unless you disable the interrupt on that processor core, the running process
can be preempted and that might happen while the process is in its critical section.
While there are multiple spin_lock_XXX apis to disable interrupts, you might want to use
the spin_lock_irqsave as it saves the interrupt flags on that core and restores them while releasing the lock.
New contributor
add a comment |
up vote
1
down vote
What does it mean by code holding semaphore can be preempted?
It means that a process that is currently running in its critical section holding some lock for the purpose of synchronization can be preempted. Ideally interrupts have the highest
priority, so unless you disable the interrupt on that processor core, the running process
can be preempted and that might happen while the process is in its critical section.
While there are multiple spin_lock_XXX apis to disable interrupts, you might want to use
the spin_lock_irqsave as it saves the interrupt flags on that core and restores them while releasing the lock.
New contributor
add a comment |
up vote
1
down vote
up vote
1
down vote
What does it mean by code holding semaphore can be preempted?
It means that a process that is currently running in its critical section holding some lock for the purpose of synchronization can be preempted. Ideally interrupts have the highest
priority, so unless you disable the interrupt on that processor core, the running process
can be preempted and that might happen while the process is in its critical section.
While there are multiple spin_lock_XXX apis to disable interrupts, you might want to use
the spin_lock_irqsave as it saves the interrupt flags on that core and restores them while releasing the lock.
New contributor
What does it mean by code holding semaphore can be preempted?
It means that a process that is currently running in its critical section holding some lock for the purpose of synchronization can be preempted. Ideally interrupts have the highest
priority, so unless you disable the interrupt on that processor core, the running process
can be preempted and that might happen while the process is in its critical section.
While there are multiple spin_lock_XXX apis to disable interrupts, you might want to use
the spin_lock_irqsave as it saves the interrupt flags on that core and restores them while releasing the lock.
New contributor
New contributor
answered Nov 8 at 10:04
AbhishekChoubey
111
111
New contributor
New contributor
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53126351%2fwhat-does-it-mean-by-code-holding-semaphore-can-be-preempted%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
The problem with your question is that we do not know the context. What kind of semaphore? It is possible for a kernel to implement a semaphore so that the process holding it cannot be preempted. Or it a semaphore could be implement so that the process holding it could not be preempted.
– user3344003
Nov 2 at 22:32
Yes, but according to my understanding we can't implement a semaphore which cannot be preempted right when the interrupt occurs?
– Smita
Nov 2 at 22:59
You could block preemption as part of grabbing the semaphore. That's not normal but it could be done.
– user3344003
Nov 3 at 0:21