“This is the 25th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

preface

Hello! Friend!!!

Thank you very much for reading haihong’s article, if there are any mistakes in the article, please point out ~

 

Self-introduction ଘ(੭, ᵕ)੭

Nickname: Haihong

Tag: programmer monkey | C++ contestant | student

Introduction: because of C language to get acquainted with programming, then transferred to the computer major, had the honor to get some national awards, provincial awards… Has been confirmed. Currently learning C++/Linux/Python

Learning experience: solid foundation + more notes + more code + more thinking + learn English well!

6.4 Reader writer problem

1, in the reader writer problem, can simultaneously perform reading and writing is (). C. Readers and writers B. different writers C. different readers D. Neither

2. In the reader-first reader-writer problem, readers can enter the premise of reading (). A. No reader or writer is reading b. No reader is reading C. No writer is writing D. The writer is waiting

3, in the reader code rc–; If (rc==0) V(W) in V(W) may wake up other readers. x

Explanation: This is the last reader

4. Reader-first reader-writer problems in which a writer comes first, but may run after a later reader. Square root

Only if there is no reader reading, the writer can enter the writing. x

Explanation: if another writer is writing, the writer is still not allowed to write.

6.5 The dining problem of philosophers

1. The solution to the philosopher’s dining problem is as follows:

semephore *chopstick[5]; semaphore *seat; Philosopher I:... P(seat); P(chopStick[i]); P(chopStick[(i + 1) % 5]); (chopStick to eat V [I]); V(chopStick[(i + 1) % 5]); V(seat);Copy the code

Explanation: Where, the initial value of seat is ().C A.0 B.1 C.4 D.5

2. In the philosopher’s dining problem, there is the following code:

		 P(m);
        test(i);
        V(m);
Copy the code

Critical resources in test[I] include (). B A.state[i] B.state[(i+1)%5] C.ph[i] D. other

3. When the semaphore value is 2, it means (). A. There are two processes waiting on the semaphore. B. There are two semaphore available C. The semaphore is a synchronous semaphore d. the semaphore is a binary semaphore

If you give 5 philosophers 6 chopsticks, there will be no deadlock. Square root

5. The P and V operations on mutex semaphore are generally in different processes. x

6.6 monitor

1. There is no () in the pipe process after the condition variable is introduced. C. A, B, C, D

2. Q is allowed to wait until Q leaves the queue. A. have B. have C. have D. have The system monitor

Explanation: 3. There can only be one condition variable per procedure.x

4. In Hoare pipe, when a process P in a pipe calls X. wait(), if the emergency queue is not empty, it will wake up the waiting process in the first entry queue, and P enters the conditional queue of X. x

Explanation:

Semaphore synchronization is available in both Linux and Windows systems. Square root