Machine-translated by Google. Questions are authored in English.
Top

Inter Task Communication Questions and Answers

Answer: A

Two tasks reading, modifying and writing the same variable can interleave so that one update is lost, and whether they do depends on when the preemption falls. The bug therefore appears intermittently and often only under load.

Please log in or register to report this question.

Answer: B

Correct answer: a preemption between the read and the write loses one update

Incrementing a variable is three operations - read, modify, write - and a preemption between them lets another task read the same old value, so one of the two increments disappears. The remedy is a lock, a critical section, or an atomic instruction, according to how long the sequence is.

Please log in or register to report this question.

23.

Two tasks each execute this on a shared counter, with no protection.

int t = count;
t = t + 1;
count = t;

Starting from zero, the final value may be

Answer: C

If either task completes all three lines before the other begins, the answer is two; if both read before either writes, one increment is lost and the answer is one. That the answer is not determinate is the whole meaning of a race.

Please log in or register to report this question.

Answer: D

The qualifier stops the compiler caching the value in a register; it says nothing about a preemption falling between two machine instructions. Believing otherwise is one of the most persistent misconceptions in embedded C.

Please log in or register to report this question.

Answer: A

A processor or compiler may complete accesses out of program order, which matters when another core or a peripheral observes them. A barrier forbids the reordering across a chosen point, and it is quite separate from the mutual exclusion a lock provides.

Please log in or register to report this question.

Answer: B

One semaphore counts empty slots and blocks the producer when the buffer is full; the other counts full slots and blocks the consumer when it is empty. A mutex is added where several producers or consumers share the structure.

Please log in or register to report this question.

Answer: C

Correct answer: needs no data to be moved when an item is removed

A linear buffer must shuffle its contents down when the front item is taken; a ring simply advances the read index, which is one operation whatever the buffer holds. That makes the cost of insertion and removal constant, which is what an interrupt handler needs.

Please log in or register to report this question.

Answer: D

The producer advances the write index and reads the read index; the consumer does the reverse. With aligned single-word indices and the right barriers no lock is needed, and adding a second producer destroys the property immediately.

Please log in or register to report this question.

Answer: A

Correct answer: distinguish the full condition from the empty one

With the indices equal in both cases, full and empty are indistinguishable. Leaving one slot unused means the buffer is full when advancing the write index would reach the read index, and empty when the two are equal - two conditions now told apart, at the cost of one slot. The alternative is to keep a separate count.

Please log in or register to report this question.

30.

A ring buffer declared with 16 slots and the one-empty-slot convention can hold at most

Answer: B

One slot is given up so that full and empty remain distinguishable, so fifteen is the usable capacity. Sizing the array to a power of two lets the index wrap by a mask rather than a division, which is why sixteen was chosen.

Please log in or register to report this question.

Loading…
Tags: Inter Task Communication Questions and Answers || Inter Task Communication MCQ Questions and Answers || Inter Task Communication GK Questions and Answers || Inter Task Communication GK MCQ Questions || Inter Task Communication Multiple Choice Questions and Answers || Inter Task Communication GK || GK on Inter Task Communication || Embedded Systems Questions and Answers || Embedded Systems MCQ Questions and Answers || Embedded Systems GK Questions and Answers || GK on Embedded Systems