2014年12月25日 星期四

C++ Job Interview Questions

1. What is a call back function?

When a function is being executed, it is called and it is a callee.
Sometimes a function can take a function pointer or function object form the caller.
That function is a call-back function because the callee calls back the caller.
For example, if you call me to write a software and call you back afterward by phone, the phone call is a call-back function. After I called you back, you may do something you want, e.g. make a report mentioning Ricky has done some jobs, notice the customer that the job is done, etc. I, as a callee, do not need to care about what the caller will do, and I just need to perform my job and remember to call the call-back function at a suitable time.

One use of the call back function is to make notification or display message. Another possible use of call-back function can be used in a quick sort function that takes a comparator function written by the caller to define how to perform specific sorting.

2. What is function pointer?

3. What is function object?

4. What is static in C++?

5. What is const in C++?

6. What is a deadlock?
1. Mutual Exclusion a resource can be hold/locked by exactly one process.
2. Hold and wait means all processes are holding a resource, and are waiting some other resource.
3. Non-Preemption means in case a resource is held, other processes cannot preempt it and needs to wait it.
4. Circular Wait means P0 waits P1, P1 waits P0.

7. How to avoid deadlock?
Use deadlock prevention and deadlock avoidance.
Deadlock Prevention
1. Kill Mutual Exclusion by makes the resource sharable, e.g. a file can be shared. 
2. Kill Hold and Wait by forcing the processes to hold all necessary before execution. If any of the resource is not held, it releases all its held resources. Equivalently, a process can perform partial execution after holding some resources. But when it needs to further make a request to a resource, it needs to release all its held resource before making a requesting.
3. Kill Preemption. It is not feasible.
4. Kill Circular Wait by making all the resources in sequence by an ID. All processes making a request to hold a resource needs to according to the defined resource sequence.

沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...