We hold a large number of creative competitions and contests in computer science and programming. These are school olympiads, such as the All-Russian School Team Olympiad , the Information Technologies Olympiad and the IEPI . We also organize student Olympiads, in particular, the semi-final of the ICPC World Programming Championship.When working on the “Programming and Information Technologies” direction, we took into account the rich experience in conducting other thematic competitive events in the IT sphere and the expertise of our colleagues. For example, since this year, the author and developer of the Codeforces portal Mikhail Mirzayanov has been working at ITMO University.
Example task: Given a code in an abstract programming language imitating the work of a request queue.Further, as an example, we give the task from the final stage. This is the task of operating systems and process scheduling.Code for the task
queue tasks; task worker_task; void do_task(task) { sleep(random()) : } void request() { while (true) { new_task = new task(); if (worker_task == null) worker_task = new_task; else if (queue.size() < 5) queue.push(new_task) sleep(random()) } } void worker() { while (true) { if (worker_task == null) { sleep(1000); } else { do_task(worker_task); if (queue.notEmpty()) worker_task = queue.pop(); } } } main() { thread worker_thread(worker); for (int i = 0; i < N; ++i) { threadr tr(request) } }
In a separate thread, the worker process is started, which processes tasks coming from N (N> 1) request threads. The do_task method imitates task execution.
Which of the following statements are true?
- Race condition on worker_task variable
- The queue queue can contain 6 items.
- The system may stop performing tasks, even if the queue is not empty.
- The system will always carry out tasks if they arrive,
- The system is guaranteed to perform all incoming tasks.
Answer: 1, 2, 3
Example of a problem: Consider a computer system with one central processor, which at a time can calculate only one process. The system time is discrete and is measured in arbitrary cycles.Great information on the topic can be found in thematic programming courses from the approved list on the Olympiad website .Continuation of the text of the taskThere are three job sources in the system. Each task generates a process that terminates at the end of the calculations. For each task source, the number of the cycle in which the first task from this source appeared, the number of ticks, after which each next task appears and the number of ticks needed to complete the task from this source (all tasks from one source require the same time to perform) .
A multi-level queue is used to control the order in which tasks are executed. For each source its own FIFO queue is formed from the tasks of this source. Queues are prioritized. The process of performing a specific task can only be started if there is not a single task in any queue with a higher priority.
The task that appears immediately at the same time begins to run if the processor is free or rises in turn for execution. After the start of execution, the process is not interrupted until it is completed. If the execution of the next process is completed, then in the next clock cycle, the process is selected from the highest priority of the non-empty queues. In this choice is involved, and the task that appeared in this beat.
The response time will be the number of cycles that have passed since the appearance of a particular task until the end of its execution. We will consider an accident when the response time of one of the tasks has exceeded 50 cycles.
Determine the minimum number of clock cycles until the next source 3 - X task appears, at which the system will operate indefinitely without an emergency.
- We assume that the time of the appearance of the task, this is the initial moment of the specified measure. Accordingly, when we say that the first occurrence time from the source is 1, and the number of time periods before the next task is 5, then the second task from this source will appear at the beginning of step 6.
- The time required for switching for the next task will be considered irrelevant and not taken into account when solving the task.
- Each source has an independent numbering of tasks, starting with 1.
Answer: 24
Source: https://habr.com/ru/post/430742/
All Articles