tailieunhanh - Bài giảng Hệ điều hành nâng cao (Operating System-OS): Chương 6 - Phan Vĩnh Thuần

Chương 6 - threads. Bài giảng gồm có những nội dung chính sau: Introduction to multimedia, multimedia files, video compression, multimedia process scheduling, multimedia file system paradigms, file placement, caching, disk scheduling for multimedia. | Chapter 6. Process Synchronization OBJECTIVES We discuss various mechanisms to ensure the orderly execution of cooperating processes that share a logical address space, so that data consistency is maintained. To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data. To present both software and hardware solutions of the critical-section problem. . Background The bounded buffer can be used to enable processes to share memory. The following variables reside in a region of memory shared by the producer and consumer processes See 97 #define BUFFER_SIZE 10 typedef struct{ . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; The shared buffer is implemented as a circular array with two logical pointers: in and out. The variable in points to the next free position in the buffer; out points to the first full position in the buffer. The buffer is empty when in == out The buffer is full when ((in+1)%BUFFER_SIZE) == out. The producer process has a local variable nextProduced in which the new item to be produced is stored. The consumer process has a local variable nextConsumed in which the item to be consumed is stored. The producer process. while (true) { /* produce an item in nextProduced */ while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; } The consumer process. while (true) { while (in == out) ; //do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in nextConsumed */ } This is a model of a system consisting of cooperating sequential processes, all running asynchronously and possibly sharing data. This scheme allows at most BUFFER_SIZE-1 items in the buffer at the same time. Suppose we want to modify the algorithm to remedy this deficiency. One possibility is to add an integer variable counter initialized to 0. counter is incremented every time we add a new item to the buffer. counter is . | Chapter 6. Process Synchronization OBJECTIVES We discuss various mechanisms to ensure the orderly execution of cooperating processes that share a logical address space, so that data consistency is maintained. To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data. To present both software and hardware solutions of the critical-section problem. . Background The bounded buffer can be used to enable processes to share memory. The following variables reside in a region of memory shared by the producer and consumer processes See 97 #define BUFFER_SIZE 10 typedef struct{ . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; The shared buffer is implemented as a circular array with two logical pointers: in and out. The variable in points to the next free position in the buffer; out points to the first full position in the buffer. The buffer is empty when in == out The buffer is full when ((in+1)%BUFFER_SIZE) ==

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.