Asynchronous Flashcards

1
Q

What does a task cariable represent?

A

A task variable represents an ongoing process for the call with a commitment to produce an value when the work is complete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why to use async methods

A

You use them on calls that expect to take longer than usual and in mean while uou can continue with other code execution . You should await the task variable before you can work on it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens when a task is awaited?

A

Awaiting on the task usually means waiting on the task . So, when control hits await statement it returns to the calling method with a task . If there is no other work to be done even in the calling method it simply waits till the task brings back the value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens if a call to async method executes even before it result is awaited?

A

Nothing specifically happens. Because task is not awaited ( not waiting) the control completely goes out of the current method having async call to the calling method with a task value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Do async and await create threads?

A

Async methods are intended for non-blocking operations. The async and await keywords don’t cause additional threads to be created . You can still use Task.run() to move CPU bound work to back ground thread . But a back ground thread for process just waiting on results like api call , db call won’t help

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does Program and Process mean?

A

Program is the passive state of code that resides on hardware . When program is run it moves to RAM becomes active and turns into process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What components are created in RAM when program is set to execute on RAM?

A

Process control block - stores metadata of process , Process Address Space - stores variables and objects needed by process, procee paging table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does process control block contains?

A

It is a datastructure containing processid , listoffiles used by process , memory limits of process address space and copy of registers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does process address space contains?

A

It contains code of the process . Stack - for primitive variables and Heap - for objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is program counter?

A

Program counter is a register that contains the address of next instruction to execute and is in CPU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does CPU execute different processes?

A

If clock speed is 3 GHz , it means CPU can execute 3 * 10(9) operations per second . So if there are 30 processes then CPU can execute 10(8) processes of all processes per second.To the user it looks like all the processes execute at the sametime but in reality each instruction executes one by one . This illusion is called CPU scheduling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is CPU scheduling?

A

OS moves the CPU across live processes in RAM . CPU would execute instructions of all processes one at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is context switch?

A

Switch between process that includes sending the value of registers in CPU to PCB of current executing process and fetching the value of registers from PCB of the next processs that needs to be executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is thread?

A

A thread is a unit of execution in the process executed by the Core in a CPU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Will context switching happen between threads?

A

Yes context switching do happen between the threads of a same process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can multiple threads share memory?

A

Each thread will have its own copy of registers , stack memory but can share same heap memory

17
Q

Will CPU run multiple threads simultaneously

A

CPU seems to be run multiple threads and process at the same time but this is an illusion , actually at any point of time only single thread is executed this is concurrent execution where each instruction of a thread / process is exectued one at a time