For each of the following, state whether the CPU, IO controller, or both determines when it occurs. (i.e., initiates it)
Programmed IO (PIO)
Select all possible options that apply.
Direct Memory Access (DMA)
Select all possible options that apply.
Interrupts
Select all possible options that apply.
Polling
Select all possible options that apply.
Which of the following (if any) prints the sum of the first 256 bytes of disk block 1234? Assume that the arguments to async_read are correctly set, that it performs the PIOs to request the block data be transferred into buf, and that it enqueues sufficient information so that the interrupt service routine can call the specified event handler (if this is necessary).
A:
char buf\[256\];
void ps(){
async\_read(1234, buf, 256);
int s\=0;
for (int i\=0; i<256; i++)
s += buf\[i\];
print("%d\\n", s);
}
B:
int getsum(char\* buf) {
int s\=0;
for(int i\=0; i<256; i++)
s += buf\[i\];
return s;
}
char buf\[256\];
void ps(){
int s \= async\_read(1234, buf, 256, getsum);
print("%d\\n", s);
}
Which of the following statements best describes this code that is attempting to print the value of a disk block. Note that syntax of queue has changed slightly from the assignment to simplify it.
void interrupt\_service\_routine(){
int\* result;
void (\*callback)(int\*);
queue\_dequeue(&result, &callback);
callback(result);
}
void printInt(int\* i){
printf("%d\\n", \*i);
}
void read(int blockno){
int\* result \= malloc(sizeof(int));
queue\_enqueue(result, printInt);
disk\_read(result, blockno);
free(result);
}
Which of the following best describes what happens to a thread when it calls the following functions? Answer each subquestion separately (i.e., previous subquestions have no effect on subsequent ones).
uthread_create(proc, arg)
uthread_block
uthread_unblock
uthread_join(t)
t switches to a different CPU core and starts executing there.t blocks until the current thread finishes.t has completed, it is freed immediately, otherwise t is tagged to be freed once it completes.t has completed, it is freed immediately, otherwise the current thread blocks until t finishes.t and then continues running.t is preempted and forced to yield to another thread.t is freed immediately, and will not be able to execute anymore.uthread_yield
uthread_detach(t)
t is blocked until some thread calls uthread_join(t).t is freed immediately, and will not be able to execute anymore.t is preempted and forced to yield to another thread.t has completed, it is freed immediately, otherwise t is tagged to be freed once it completes.t has completed, it is freed immediately, otherwise the current thread blocks until t finishes.et switches to a different CPU core and starts executing there.Which of the following statements best describes the comparison between these two blocks of code? Assume that foo's runtime is known, and that the code will not be interrupted or otherwise disrupted from outside the program.
A:
thread\_t t0 \= uthread\_create(foo, NULL);
thread\_t t1 \= uthread\_create(foo, NULL);
thread\_t t2 \= uthread\_create(foo, NULL);
uthread\_join(t0);
uthread\_join(t1);
uthread\_join(t2);
thread\_t t3 \= uthread\_create(foo, NULL);
uthread\_join(t3);
B:
thread\_t t0 \= uthread\_create(foo, NULL);
uthread\_join(t0);
thread\_t t1 \= uthread\_create(foo, NULL);
uthread\_join(t1);
thread\_t t2 \= uthread\_create(foo, NULL);
uthread\_join(t2);
thread\_t t3 \= uthread\_create(foo, NULL);
uthread\_join(t3);