Hardware interview practice
Mailbox peek and blocking put
Which behavior is guaranteed for this bounded mailbox?
Starting point
Question code
mailbox #(int) m = new(1);
fork
begin
m.put(7);
m.put(8);
end
begin
int v;
#2 m.peek(v);
#2 m.get(v);
end
joinChoose one
Answer choices
- A. peek removes 7 at time 2, so put(8) completes then
- B. put(8) overwrites 7 immediately
- C. peek returns 7 without freeing space; put(8) remains blocked until get removes 7 at time 4, then 8 can be inserted
- D. get returns 8 at time 4 because peek advances the mailbox cursor
