|
-
October 17th, 2007, 12:30 AM
#1
Is it possible to ensure a piece of code executed without context switch?
I need to send 256 bytes over serial port without any interrupt, it will take less than 500 ms, but any context switch will fail the task. Is it possible to make this short period of time no context switch?
-
October 17th, 2007, 11:10 AM
#2
Re: Is it possible to ensure a piece of code executed without context switch?
Not in Windows OS. But, what I don't understand is, how the context switch is affecting your task ? I'd be curious to know more details, if possible.
-
October 19th, 2007, 11:47 AM
#3
Re: Is it possible to ensure a piece of code executed without context switch?
As kirants already pointed out, Windows will context-switch whenever it likes, you can't influence that. You will need a hard-realtime OS for that.
Having said that, you may want to try sending the 256 bytes in one single WriteFile call to the port. I'm not too familiar with the underlying driver layers, but you may find that the complete buffer of 256 bytes is handed to the port driver "as-is" and that the action from there on is completely interrupt driven. If this assumption is true then the driver will not be affected by context switching.
-
November 16th, 2007, 12:14 AM
#4
Re: Is it possible to ensure a piece of code executed without context switch?
One 'hack' is to raise the thread priority to Real Time for that portion of the code. But there are no gaurantees even then because
1. There may be other (system) threads running at that priority.
2. Your thread may 'wait for something' i.e. enter blocked/not runnable state in the middle of the operation. E.g. during many kind of I/O operations, the thread would be waiting for e.g. things to be send out to port etc.
But having said that, boosting priority to highest level (for short time) does the trick at times.
Say no to supplying ready made code for homework/work assignments!!
Please rate this post!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|