Graded Quiz Unit 3 Attempt Review PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Suleman Ismaila

Home  My courses  CS 3307 - AY2020-T5  2 July - 8 July  Graded Quiz Unit 3

Started on Thursday, 2 July 2020, 10:41 PM


State Finished
Completed on Thursday, 2 July 2020, 10:51 PM
Time taken 9 mins 53 secs
Marks 20.00/20.00
Grade 100.00 out of 100.00

Question 1 Correct Mark 1.00 out of 1.00

True or False: Lookups simply read the data structure; as long as we can guarantee
that no insert is on-going, we can allow many lookups to proceed concurrently.

Select one:

True

False

The correct answer is 'True'.

/
Question 2 Correct Mark 1.00 out of 1.00

True or False: Condition variable is an explicit queue that threads can put
themselves on when some state of execution (i.e., some condition) is not as desired
by waiting on the condition.

Select one:

True

False

The correct answer is 'True'.

Question 3 Correct Mark 1.00 out of 1.00

True or False: To use a condition variable, one has to in addition have a lock that is
not associated with this condition.

Select one:

True

False

The correct answer is 'False'.

Question 4 Correct Mark 1.00 out of 1.00

True or False: In a multi-threaded application, the developer has full control over
what is scheduled at a given moment in time; rather, the programmer simply
creates threads and then hopes that the underlying OS schedules them in a
reasonable manner across available CPUs.

Select one:

True

False

The correct answer is 'False'.

/
Question 5 Correct Mark 1.00 out of 1.00

When does the deadlock occur in this code?

Thread 1: Thread 2:
lock(L1); lock(L2);
lock(L2); lock(L1);

Select one:

a. Thread 1 grabs lock L1

b. Thread 2 grabs L2 and tries to acquire L1

c. Thread 1 grabs lock L1 and then a context switch occurs to Thread 2, then Thread 2
grabs L2 and tries to acquire L1

d. Deadlock does not necessarily occur

The correct answer is: Thread 1 grabs lock L1 and then a context switch occurs to Thread 2,
then Thread 2 grabs L2 and tries to acquire L1

Question 6 Correct Mark 1.00 out of 1.00

True or False: Atomicity violation  bugs and order violation bugs are examples of
Non-deadlock bugs.

Select one:

True

False

The correct answer is 'True'.

/
Question 7 Correct Mark 1.00 out of 1.00

POSIX threads library are those for providing mutual exclusion to a critical section
via:

Select one:

a. API’s

b. Multi-threaded

c. locks

d. Keys

The correct answer is: locks

Question 8 Correct Mark 1.00 out of 1.00

True or False: Concurrent data structures can be queues lists and counters only.

Select one:

True

False

The correct answer is 'False'.

/
Question 9 Correct Mark 1.00 out of 1.00

What command would you change to switch the letter printed by T2:

Time increases in the downwards direction, and each column shows when a
di erent thread (the main one, or T1, or T2) is running:

main starts running


main prints "main: begin"
main creates thread T1
main creates thread T2
main waits for T1
T1 runs
T1 prints "A"
T1 returns
main waits for T2
T2 runs
T2 prints "B"
T2 returns
main prints "main: end"

Select one:

a. T1 = T2

b. T1 prints “A” or “B”

c. T2 prints “A”

d. T2 = T1

The correct answer is: T2 prints “A”

/
Question 10 Correct Mark 1.00 out of 1.00

Thread 0 holds the lock (i.e., it has called sem wait() but not yet called sem post()),
and another thread (thread 1, say) tries to enter the critical section by calling sem
wait(). In this case thread 1 must wait (putting itself to sleep and relinquishing the
processor)?

Select one:

a. thread 1will nd that the value of the semaphore is -1

b. thread 1will nd that the value of the semaphore is 1

c. thread 1will nd that the value of the semaphore is 0

d. thread 1will nd that the value of the semaphore is 2

The correct answer is: thread 1will nd that the value of the semaphore is 0

Question 11 Correct Mark 1.00 out of 1.00

Multi-Threaded Address Space is composed of all EXCEPT:

Select one:

a. Stack (1)

b. Stack (3)

c. Program code

d. Free

The correct answer is: Stack (3)

/
Question 12 Correct Mark 1.00 out of 1.00

This code is an example of receiving events via?

int select(int nfds,


fd_set *restrict readfds,
fd_set *restrict writefds,
fd_set *restrict errorfds,
struct timeval *restrict timeout);

Select one:

a. API poll ()

b. API select ()

c. Select

d. Poll

The correct answer is: API select ()

Question 13 Correct Mark 1.00 out of 1.00

The following are all key concurrency terms EXCEPT:

Select one:

a. Mutual Exclusion

b. Non-Critical Section

c. Race Condition

d. Intermediate

The correct answer is: Non-Critical Section

/
Question 14 Correct Mark 1.00 out of 1.00

Spin locks must be all of the following EXCEPT:

Select one:

a. Simple

b. Correct

c. Fair

d. Perform

The correct answer is: Simple

Question 15 Correct Mark 1.00 out of 1.00

The following stores the state of each thread:

Select one:

a. TCB

b. PCB

c. T1

d. T2

The correct answer is: TCB

/
Question 16 Correct Mark 1.00 out of 1.00

What capability allows multiple people to use one system at the same time?

Select one:

a. Multi-thread

b. Multi-user

c. Distributed Processing

d. Multitasking

The correct answer is: Multi-user

Question 17 Correct Mark 1.00 out of 1.00

True or False: Locks work through mutual exclusion which preventing multiple
threads from entering a critical section.

Select one:

True

False

The correct answer is 'True'.

/
Question 18 Correct Mark 1.00 out of 1.00

Imagine two producers (Pa and Pb) both calling into put() at roughly the same time.
Assume producer Pa gets to run rst, and just starts to ll the rst bu er entry ( ll
= 0 at line f1). Before Pa gets a chance to increment the ll counter to 1, it is
interrupted. Producer Pb starts to run, and at line f1 it also puts its data into the
0th element of bu er, what happens to the old data?

sem_t empty;
sem_t full;
void *producer(void *arg) {
int i;
for (i = 0; i < loops; i++) {
sem_wait(&empty); // line p1
put(i); // line p2
sem_post(&full); // line p3
}
}
void *consumer(void *arg) {
int i, tmp = 0;
while (tmp != -1) {
sem_wait(&full); // line c1
tmp = get(); // line c2
sem_post(&empty); // line c3
printf("%d\n", tmp);
}
}
int main(int argc, char *argv[]) {
// ...
sem_init(&empty, 0, MAX); // MAX bu ers are empty to begin with...
sem_init(&full, 0, 0); // ... and 0 are full
// ...
}

Select one:

a. Backed up

b. Saved

c. Overwritten

d. Value = 0

The correct answer is: Overwritten /


Question 19 Correct Mark 1.00 out of 1.00

How many times will this event loop execute?

e
while (1) {
events = getEvents();
for (x in events)
processEvent(x);
}:

Select one:

a. e

b. 1

c. x

d. Null

The correct answer is: x

/
Question 20 Correct Mark 1.00 out of 1.00

What is the purpose of this code?

// basic node structure


typedef struct __node_t {
int key;
struct __node_t *next;
} node_t;
// basic list structure (one used per list)
typedef struct __list_t {
node_t *head;
pthread_mutex_t lock;
} list_t;
void List_Init(list_t *L) {
L->head = NULL;
pthread_mutex_init(&L->lock, NULL);
}
int List_Insert(list_t *L, int key) {
pthread_mutex_lock(&L->lock);
node_t *new = malloc(sizeof(node_t));
if (new == NULL) {
perror("malloc");
pthread_mutex_unlock(&L->lock);
return -1; // fail
}
new->key = key;
new->next = L->head;
L->head = new;
pthread_mutex_unlock(&L->lock);
return 0; // success
}
int List_Lookup(list_t *L, int key) {
pthread_mutex_lock(&L->lock);
node_t *curr = L->head;
while (curr) {
if (curr->key == key) {
pthread_mutex_unlock(&L->lock);
return 0; // success
}
curr = curr->next;
}

/
pthread_mutex_unlock(&L->lock);
return -1; // failure
}

Select one:

a. Provides a failure path when the code fails.

b. pthread_mutex_unlock(&L->lock)

c. Acquires a lock in the insert routine upon entry, and only releases it on condition

d. Acquires a lock in the insert routine upon entry, and only releases it on exit

The correct answer is: Acquires a lock in the insert routine upon entry, and only releases it
on exit

◄ Self-Quiz Unit 3

Jump to...

Learning Guide Unit 4 ►

You might also like