The second application task, UpdateTask, has an endless loop that calls three functions in the following order: RetrieveData, UpdateData and StoreData. The three functions are to lie in one critical section protected by semaphore DB_IDLE. RetrieveData has no input argument and returns a pointer to a record of type DataType. The input and output arguments of UpdateData are both pointers to records of type DataType. StoreData has no input argument but produces an output argument that is 0 if a record was added successfully to the database, and is 1 if the record could not be added because the database was full. Outside of this critical section, UpdateTask is to update the global integer counter, DB_FULL, that records the number of times that calls to StoreData failed to store a record.
The third application task, CleanupData, has an endless loop that calls the function DeleteData ten times per second. DeleteData has no input argument tbut produces an output argument that is 0 if a record was deleted successfully from the database, and is 1 if no record was deleted. Function DeleteData is to be protected by semaphore DB_IDLE. Outside of this critical section, CleanupData is to update a global integer counter, DB_EMPTY, that records the number of times that calls to DeleteData failed to delete a record.
Your solution to this problem is to contain the begin() initialization routine, the startup task, and all three application tasks. Should the updates to DB_FULL and DB_EMPTY have been protected in critical sections? Are the priorities assigned to the three tasks important to the correct operation of the system?