墨爾本代寫-線上編程學術專家

Best代寫-最專業靠譜代寫IT | CS | 留學生作業 | 編程代寫Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代寫

C語言代寫 | CSC 112: Final (Sample)

C語言代寫 | CSC 112: Final (Sample)

墨尔本代写assignment,加拿大美国论文代写,北美essay代写-Panda Scholar這個作業是用C語言完成多線程、鎖相關的并發編程

CSC 112: Final (Sample)

Part 1: Possible/Impossible
Problem 1: Which of the following statements are true statements about various
page-replacement policies?
To answer: Fill in A for true statements, B for false ones.
1. The LRU policy always outperforms the FIFO policy.
2. The OPT (optimal) policy always performs at least as well as LRU.
3. A bigger cache’s hit percentage is always greater than or equal to a smaller
cache’s hit percentage, if they are using the same replacement policy.
4. A bigger cache’s hit percentage is always greater than or equal to a smaller
cache’s hit percentage, if they are using the LRU replacement policy.
5. Random replacement is always worse than LRU replacement.
Problem 2: Assume this attempted implementation of a lock:
void init(lock_t *mutex) {
mutex->flag = 0; // 0 -> lock is available, 1 -> held
}
void lock(lock_t *mutex) {
while (mutex->flag == 1) // L1
; // L2
mutex->flag = 1; // L3
}
void unlock(lock_t *mutex) {
mutex->flag = 0; // L4
}
Assume 5 threads are competing for this lock. How many threads can possibly
acquire the lock? To answer: Fill in A for possible, B for not possible.
6. 1
7. 2
8. 3
9. 4
10. 5
Problem 3: Here is a ticket lock:
typedef struct __lock_t {
int ticket, turn;
} lock_t;
Problem 4: Assume the following list insertion code, which inserts into a list
pointed to by shared global variable head:
int List_Insert(int key) {
node_t *n = malloc(sizeof(node_t));
if (n == NULL) { return -1; }
n->key = key;
n->next = head;
head = n;
return 0;
}
This code is executed by each of three threads exactly once, without adding any
synchronization primitives (such as locks). Assuming malloc() is thread-safe (i.e.,
can be called without worries of data races) and that malloc() returns successfully,
how long might the list be when these three threads are finished executing?
(assume the list was empty to begin)
To answer: Fill in A for possible, B for not possible.
Problem 5: Assume the following code, in which a “background malloc” allocates
memory in a thread and initializes it:
void *background_malloc(void *arg) {
int **int_ptr = (int **) arg; // [typo from int* -> int**
corrected here]
*int_ptr = calloc(1, sizeof(int)); // allocates space for 1 int
**int_ptr = 10; // calloc: also zeroes memory
return NULL;
}
int main(int argc, char *argv[]) {
pthread_t p1;
int *result = NULL;
pthread_create(&p1, NULL, background_malloc, &result);
printf(“%d\n”, *result);
return 0;
}
The code unfortunately is buggy. What are the possible outcomes of this code?
Assume the calls to pthread_create() and calloc() succeed, and that a NULL
pointer dereference crashes reliably. To answer: Fill in A if possible, B for not
possible.

Essay_Cheery

評論已關閉。

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信
北美代写,论文Essay代写,留学作业代写,-北美最专业的代写专家 堪培拉代写assignment,论文代写,留学作业代写-peaking代写 essay代写,assignment代写,留学生作业代写网课代做-锐 泽 代写 阿德莱德代写assignment,北美网课代修领导者,留学生网课代修代考 珀斯代写assignment,CS代写,留学生CS程序代写-Custom Writing代写 新西兰代写,math代写,新西兰Assignment代写-美 伦 代写 怎么样? 留学生CS代写,Java编程代写,网课代上代修-ezace留学生代写 达尔文代写assignment,留学生作业代写,留学代写-菠萝 菠萝蜜 代写 代写assignment,网课代上代考,考试代考论文代写-全球最好的华人代写机构 留学生代写,经济代写,代写作业-【靠谱】服务澳洲加拿大英国美国等地区