Capítulo 3 - Procesos
Capítulo 3 - Procesos
init
pid = 1
emacs tcsch
ps
pid = 9204 pid = 4005
pid = 9298
process A process A
process B
message queue
m0 m1 m2 m3 ... mn
kernel
kernel
(a) (b)
■ Datos compartidos
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
item next_produced;
while (true) {
/* produce un ítem next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* no hacer nada*/
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
item next_consumed;
while (true) {
while (in == out)
; /* no hacer nada */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
message next_produced;
message next_consumed;
while (true) {
receive(next_consumed);
/* consume un ítem en next_consumed */
}