Prevent context switch
-
As far as I know, this is something impossible on Windows. This is for security reasons: imagine you "lock" at the begining of your code but forget to "unlock". It would mean that your computer is completely frozen (only your app runs, but it can't get any input because they are not processed).
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++Yep, pretty much what I had in mind... Thanks.
-
Does anyone know of a way to prevent context switch in a block of code? As far as I can tell (unless I am wrong) Critical Sections do not guarantee not to switch context, it simply means threads can't access a shared resource. I am looking for some API that will guarantee an atomic execution of a block of code (if this API even exists) Shay
-
Does anyone know of a way to prevent context switch in a block of code? As far as I can tell (unless I am wrong) Critical Sections do not guarantee not to switch context, it simply means threads can't access a shared resource. I am looking for some API that will guarantee an atomic execution of a block of code (if this API even exists) Shay
I suppose kernel code can. See, for instance [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I suppose kernel code can. See, for instance [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]nice but in kernel I prefer to use more orthodox stuff :) My question was for something I am doing in user space.
-
You can get close by temporarily elevate the thread priority to real time. But even then there's no guarantee.
That's what I ended up doing.
-
nice but in kernel I prefer to use more orthodox stuff :) My question was for something I am doing in user space.
Well, if it is tricky in kernel space... :rolleyes:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Does anyone know of a way to prevent context switch in a block of code? As far as I can tell (unless I am wrong) Critical Sections do not guarantee not to switch context, it simply means threads can't access a shared resource. I am looking for some API that will guarantee an atomic execution of a block of code (if this API even exists) Shay
can't be done in user mode, and that is how it has to be in order to protect one user/app from another user/app. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
You can get close by temporarily elevate the thread priority to real time. But even then there's no guarantee.
Read this somewhere that calling
SetThreadPriority
also resets the quantum of the thread. So callingSetThreadPriority
repeatedly can infact give exclusive control to the thread, at least in theory. But I would never recommend elevating priority of a thread to real time. Rather you should design your code in such a way that it handles re-entrancy.«_Superman_»
I love work. It gives me something to do between weekends. -
can't be done in user mode, and that is how it has to be in order to protect one user/app from another user/app. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
Luc Pattyn wrote:
it has to be in order to protect one user/app from another user/app.
:confused:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Read this somewhere that calling
SetThreadPriority
also resets the quantum of the thread. So callingSetThreadPriority
repeatedly can infact give exclusive control to the thread, at least in theory. But I would never recommend elevating priority of a thread to real time. Rather you should design your code in such a way that it handles re-entrancy.«_Superman_»
I love work. It gives me something to do between weekends.