Several pen questions

Source: Internet
Author: User



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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.