Resource Control Issues
Posted: Wed Jun 20, 2007 8:47 pm
Ok, if I have two threads that run in infinite loops printing an increasingly large number (in the same location) I have an issue where it apprears the time slice cuts in the middle of the printf or even worse in the middle of the move cursor routines and sometimes I get charecters at random locations.
What I was think was placing a resource semaphore on the console.
So basically, if someone wanted to move the cursor, or print a charecter those routines would do something like a:
And basically this would sit in a loop and wait until the Console Semaphor was 0, and then it would jack it up to 1, and then when its operation completed, drop it back down to 0.
The functions:
RESOURCE_FREE
RESOURCE_SET
RESOURCE_CHECK
Would all be used to check / modify the state values of various elements. I was thinking I could use an array, and in this case, CONSOLE_ID would be the index in the array. I Could also have KEYBOARD_ID etc etc...
I would have to declared the volitale char RESOURCE[16]; like that right?
This way if the processes are running back and forth, only one of them could actually access the screen resources at a time, and this would save me from having to disable interrupts as an alternative approach.
Is that about right?
Thanks,
Rich
What I was think was placing a resource semaphore on the console.
So basically, if someone wanted to move the cursor, or print a charecter those routines would do something like a:
Code: Select all
REQUEST_CONSOLE();
Code: Select all
void REQUEST_CONSOLE()
{
while(RESOURCE_CHECK(CONSOLE_ID) == 1);
RESOURCE_SET(CONSOLE_ID);
}
void RELEASE_CONSOLE()
{
RESOURCE_FREE(CONSOLE_ID);
}
void putch(int c)
{
REQUEST_CONSOLE();
.... putch
RELEASE_CONSOLE();
}
void movecursor(int x, int y)
{
REQUEST_CONSOLE();
.... move cursor
RELEASE_CONSOLE();
}
RESOURCE_FREE
RESOURCE_SET
RESOURCE_CHECK
Would all be used to check / modify the state values of various elements. I was thinking I could use an array, and in this case, CONSOLE_ID would be the index in the array. I Could also have KEYBOARD_ID etc etc...
I would have to declared the volitale char RESOURCE[16]; like that right?
This way if the processes are running back and forth, only one of them could actually access the screen resources at a time, and this would save me from having to disable interrupts as an alternative approach.
Is that about right?
Thanks,
Rich