I am giving you are problem and I want it to simulate this in c++. Use thread and locks judicialy

A. Load Monitoring
The load monitoring section will collect the task load on different cores in the system and determine whether a load imbalance has occurred. In the kernel, we use the load_state_t structure to record the load information. As shown in Fig. 3, this structure records the number of ready tasks on the core, the number of sleep tasks, the currently running tasks, the queue where the sleep tasks are located, the sum of the time slice sizes of all ready tasks, and the size of each ready task and its time slice on the core.

The process of load monitoring is the process of populating the load_state_t structure based on the real-time load of the core. The load monitoring algorithm applied in this paper uses the time-slice size of the ready task on the core as the load evaluation factor
Definition 1: The sum of the time-slice sizes of all ready tasks on a single processor is regarded as the processor load which is denoted by L. And T denotes the load proportion threshold. In our design, the value of T is 20%. A denotes the average processor load of all CPUs in the current system (except where the rootserver is located). The value of L/A is referred to as the degree of load on the core. Obviously, the larger the value, the heavier the load on the core. The load state S of the core can be determined by equation 1.
S(L)=⎧⎩⎨⎪⎪heavynormal A∗(1+T)≥L≥A∗(1−T)lightL>A∗(1+T)L<A∗(1−T)L<A(1)
View SourceRight-click on figure for MathML and additional features.

In equation 1, heavy means the current processor is in a heavy load state, and the tasks need to be migrated out. Normal means the current processor is in a normal load state, and no need for load adjustment. Light means the current processor is in a light load state, and there is a waste of CPU resources, and the load can be increased by adding new tasks.

Load monitoring can be triggered in two ways. First, it is triggered when a new task is created so that the relatively free core can be found to allocate that task. Second, it is performed periodically in the rootserver to get the load status of other cores and determine whether load balancing is needed through inter-core task migration.

B. Balancing decision
From the above load monitoring, it can be found that there are two triggers for the balancing decision, triggered when a new task is created and triggered at timing. Therefore, the balancing decision algorithm needs to be designed for these two cases separately.

When a new task is created, the rootserver will use the analysis results of load monitoring to get the core ID that is relatively idle in the system and then assign the task to it. When triggered at timings, the rootserver analyzes the load on each core in the system and tries to get the task that will be migrated.

The steps of the algorithm are shown as follows.

The rootserver traverses the load of all cores, gets all ready tasks running on them and their time-slice sizes, and saves them in a two-dimensional array task_info_cpus with the task_info_t structure as a member of the array.

Based on task_info_cpus, the sum of the time-slice sizes of the ready tasks on each core is calculated and saved in the integer array named sum. Also, the average load of the cores is calculated and saved in the variable named ave.

Find out the most heavily loaded core and the least loaded core in the sum array and save their IDs in the variables named max and min.

Determine if inter-core migration of tasks is needed. If the state of the core with the heaviest load in the system is not heavy or the state of the core with the lightest load is not light, which means no load balancing is needed, there is no need to go to step (5) and the function will return null directly. Otherwise, go to step (5).

The thread task with the smallest time-slice size is selected from the most heavily loaded core, and it is determined whether load balancing can be achieved by migration of this task according to the following method.

If the load level of the currently most heavily loaded core is greater than the load level of the currently least heavily loaded core after migrating to the task thread, it means that the load level of the most heavily loaded core in the system can be reduced after completing this task migration.

Otherwise, it means that migrating the task thread only eliminates the overload on one core but adds a new overloaded core, which is insufficient to alleviate the global load imbalance. This step will directly return to null.

Write the max and min values to the memory area pointed by the from pointer and to pointer. Furthermore, return the task thread found in step (5) as the function return value.

These are the steps of the balancing decision algorithm, and after the balancing decision, we need the task migration module.

C. Task Migration
The task migration module will check if the task value returned during the load decision process is empty at first. If it is empty, the task migration is not needed, and the task is exited directly. Otherwise, it parses the task migration information and obtains the outgoing core ID and the incoming core ID. Finally, the inter-core task migration function is called to complete the final task migration. The task management module implements the inter-core task migration function, so we will not elaborate on it here.