fw Flashcards

1
Q

Race Condition

A

2 threads try to access a shared resource in a critical section of code. This leads to a sequence of behaviors where data can be accessed in a way unintended by the programmer and the behavior depends on the thread timing.

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

Mutex

A

A type of lock where only one thread can hold it

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

Synchronization

A

Co-ordination of threads to ensure that they don’t access a shared resource at the same time, can be done through methods like mutex, sempahore, etc.

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

Semaphore

A

A lock with a counter on it. Each time a thread grabs the semaphore, the counter decreases, and once the counter hits 0, then no other thread can grab it (and thus access the shared data)

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

Dead lock

A

When two or more threads are unable to run because one is waiting for another to release a lock, resulting in a stand still of the program.

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

How to increase/decrease semaphore values?

A

Semaphore is initialized at a certain value., Signal command increases the semaphore value by 1, and “wait” decreases semaphore value by 1. If the value of the semaphore is already 0, then the thread waits until the value is 1.

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

Live lock

A

Two threads respond to each other continuously, while not getting any work done.

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

Thread wait

A

The thread that called wait goes into the wait queue associated with that condition variable. Then when it is the thread’s turn to run again, and the condition variable was signaled, then the thread can go.

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

Thread signal

A

Thread signal wakes up a thread waiting on a condition variable. (doesn’t immediately stop the current thread, still need the thread to unlock).

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

Thread broadcast

A

wakes up all threads waiting on the condition variable. Every thread that is currently waiting on the condition variable is awakened and will attempt to re-acquire the mutex and proceed (note that in a single threaded system signal only activates the next thread, but broadcast would be able to allow all subsequent threads to be able to grab?)

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

Garbage Collection

A

Cleaning up memory no longer used by the program. Higher level languages have automatic garbage collection.

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

Memory Leak

A

When we allocate heap memory but forget to de-allocate it, allowing others to access it when it may not be intended to be accessed.

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

Dangling pointer

A

When we free some memory, but there is still a pointer pointed to it. If we attempt to de-reference that pointer, then we can get some undefined behavior, such as seg fault, or the program may continue and experience silent failure.

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

Pass by value vs pass by reference

A

Pass by value is where a copy of the value is passed into the function. Pass by reference is where a reference to the actual variable in memory is passed into the function, meaning altering it in the function prototype will change the contents of the memory.
You can change contents of memory of an input argument by passing in a pointer for pass by value (a copy of the address is created which still allows you to manipulate the memory there).

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

The stack in C

A

Every time a function is called, a stack (stack allocation frame) is created which contains arguments, return address, and local variables. Before the program is called the next assembly instruction after the jump is also saved to the link register so that after the function ends, we can return to that next instruction.

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

The heap in C

A

A region of memory meant to dynamic memory allocation, where the programmer can allocate and deallocate memory (malloc, free, etc). Heap holds memory indefinitely unless it is freed, however freeing it doesn’t actually explicitly delete the memory, it just marks the memory as being able to be used for reallocation.