Questions about preemptive multitasking
Posted: Tue May 19, 2020 3:52 am
I have several questions related to preemptive multitasking.
First question:
The process makes a request to the memory Manager to allocate a page, while the memory Manager is running, an interruption occurs and the scheduler switches to another task. will the memory Manager continue to work correctly after returning to the process that called it? As far as I understand, during the process switching, the scheduler should remember all its registers and when it returns, the processor will continue working from the place where it was interrupted thanks to instruction pointer. Right?
Second question(extremely difficult for reading)):
Let's imagine that there are 2 processes(A and B) and they make a request for memory allocation.
In the memory Manager, when allocating, there are various variables (for example, there is a variable that stores the number of pages that follow each other at the address).
Process A tries to get memory, it calls the function that searches for pages, while running the memory allocation function remembers information about the found pages, but does not have time to finish the work correctly(the task was switched), process B makes a request for page allocation, it marks the desired pages and successfully allocates pages, the process switches, process A continues to allocate memory, but because of process B(which has already occupied that memory area), it allocates it a second time, how to avoid such situations? How real is this problem?
Third question:
What is the optimal frequency to set for IRQ0?
I set 50 Hz(20 ms), every tick I want to change the task.
Where can I read about implementing preemptive multitasking?
First question:
The process makes a request to the memory Manager to allocate a page, while the memory Manager is running, an interruption occurs and the scheduler switches to another task. will the memory Manager continue to work correctly after returning to the process that called it? As far as I understand, during the process switching, the scheduler should remember all its registers and when it returns, the processor will continue working from the place where it was interrupted thanks to instruction pointer. Right?
Second question(extremely difficult for reading)):
Let's imagine that there are 2 processes(A and B) and they make a request for memory allocation.
In the memory Manager, when allocating, there are various variables (for example, there is a variable that stores the number of pages that follow each other at the address).
Process A tries to get memory, it calls the function that searches for pages, while running the memory allocation function remembers information about the found pages, but does not have time to finish the work correctly(the task was switched), process B makes a request for page allocation, it marks the desired pages and successfully allocates pages, the process switches, process A continues to allocate memory, but because of process B(which has already occupied that memory area), it allocates it a second time, how to avoid such situations? How real is this problem?
Third question:
What is the optimal frequency to set for IRQ0?
I set 50 Hz(20 ms), every tick I want to change the task.
Where can I read about implementing preemptive multitasking?