Source: http://topic.csdn.net/u/20081123/19/87347aa7-fa61-42e2-8076-e2a8f638d1ce.html
I. programming questions (30 points)
Modern processors provide compare-and-swap atomic operations:
Int compare_and_swap (int * PV, const int CV, const int NV );
That is, compare * PV and cv. If they are equal, replace * PV value with NV and return * PV original value; otherwise, return * PV value.
Use the preceding atomic operations to perform the following operations:
Int inc_if_gt_zero (int * PV );
If * PV> 0, add * PV 1 and return * PV after modification. Otherwise, * PV is returned.
The result is thread-safe and does not use locks, traffic signals, mutex, critical section, or similar mechanisms.
Int inc_if_gt_zero (int * PV)
{
Return compare_and_swap (PV,-(* PV), * PV) = 0? 0: compare_and_swap (PV, ABS (* PV), * PV + 1 );
}
Ii. algorithm questions (35 points)
Assume there is one machine A, with 1 GB of memory, and several other machines (B, c, d ......) Data is transmitted to machine a over TCP, and machine a writes the received data to the hard disk. Data of machines such as B, C, and D is transmitted by record. The size of each record ranges from 1 Mbit/s to 1 Mbit/s ~ 16 m.
To ensure the atomicity of each record, machines such as B, C, and D first report the data size to a and then transmit the data.
When the data volume is large, machine A assigns a sequence number to the record. Each record is written in sequence and atom when a file is written.
The processing speed and network speed of machines such as B, C, and D are different. Therefore, after the data size is reported, the order in which the record data is transmitted to a may not necessarily arrive in the assigned sequence number order.
Now we need to design a data structure for the program on a. This data structure can efficiently receive data and write data to the disk in an orderly and efficient manner (that is, records with a large serial number cannot be written first, and then write back records with a smaller serial number. The disk cannot be written once if dozens of bytes are received ).
Iii. System Design Questions (35 points)
Most of the memory of the existing computer is volatile memory, and all the data in the memory will be lost once the power is down. Therefore, the design of the operating system fully considers the volatile memory features.
Q: If all the memory in the future is non-volatile memory, how should we design a new operating system or modify and improve the existing operating system?