Packet Distribution

The following part of the C code distributes packets from the input track to the output track:

void* take_and_put(void *arg)
{
    sem_wait(&semaphore);
    take();
    sem_post(&semaphore);

    pthread_mutex_lock(&mutex);
    put();
    pthread_mutex_unlock(&mutex);

    return NULL;
}

Where semaphore and mutex are initialized with:

// int sem_init(sem_t *sem, int pshared, unsigned int value);
sem_init(&semaphore, 0, 3);
// int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
pthread_mutex_init(&mutex, NULL);

If the function take_and_put is repeatedly called by a large number of threads, select correct statements about the take_and_put function.

(Select all acceptable answers.)

A thread started with the function take_and_put can call the function take even if another thread is already inside the take part of take_and_put.
A thread started with the function take_and_put can call the function put even if another thread is already inside the put part of take_and_put.
If one thread blocks at take indefinitely, other threads will still be able to start and finish take_and_put.
If one thread blocks at put indefinitely, other threads will still be able to start and finish take_and_put.
If the function take locks mutex at its start and unlocks mutex on its end, the code will eventually end in a deadlock.
   

Tags
Embedded Systems Critical section Mutex Semaphore Public New
Easy

5min

Score Distribution
Not enough data for chart
Would you like to see our other questions?

We have 750+ premium hand-crafted questions for 50+ job skills and 15+ coding language. We prefer questions with small samples of actual work over academic problems or brain teasers.

Visit our question library

Private Concierge

Send us an email with an explanation of your testing needs and a list of candidates. We will create an appropriate test, invite your candidates, review their results, and send you a detailed report.

Contact Private Concierge

Would you like to see our tests? The following tests contain Embedded Systems related questions:
On the TestDome Blog

Screening Applicants: The Good, the Bad and the Ugly

Since we’re all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they’ve been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts disagree with each other. Everybody praises their pet method and criticizes the others. Many of these methods look legitimate, but are based on...