Systems Final - MEGASET!!! all of the sets in one

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/249

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

250 Terms

1
New cards

multithreading

multiple tasks in one program

2
New cards

multitasking

multiple processes in a program (fork/exec/wait)

3
New cards

what is the problem with multitasking using processes?

being separate is safe but coordination is difficult, need to communicate between processes to update data

4
New cards

what is the main difference with multithreading

shared access to mutable data

5
New cards

pthread_t

thread identifier (TID), integer value

6
New cards

pthread_t pthread_self (void)

returns TID of the calling thread

7
New cards

int pthread_create(

pthread_t *tid,

pthread_attr_t *attr,

void (thread_fun) (void *),

void *arg

);

tid -> OUTPUT: TID of created thread

attr ->INPUT: additional features for thread, use NULL for default

thread_fun -> function thread will execute

arg -> arguments to pass to thread

8
New cards

int pthread_join (

pthread_t tid,

void **rval

);

retrieves return value of specified thread, blocks if thread has not yet terminated

tid -> tid of thread we are joining too

rval -> void pointer returned by thread, need to cast to check value

9
New cards

int pthread_detach (pthread_t tid);

makes thread unjoinable (cleans up after itself)

10
New cards

main difference between processes and threads?

processes have clear parent-child relationship, while all threads are peers

11
New cards

non determinism

outcome/behavior of program is not solely determined by input

12
New cards

race conditions

occurs whenever a programs behavior is determined by external timing

13
New cards

non critical race condition

different behavior, same outcome (we don't need to worry)

14
New cards

critical race condition

different outcome

15
New cards

data races require three conditions

1) shared mutable data

2) accessed by multiple threads, without coordination

3) at least one thread modifies the data

16
New cards

why do we need to worry about data races?

no guarantee of what happens in programs that have them, especially bad in real world applications like banking

17
New cards

sequential consistency

model of memory where all accesses can be placed in some consistent order (every read happens before or after a given write, NOT during)

18
New cards

how to prevent data races?

coordinate use of shared data

19
New cards

memory fences

pause operation on a CPU until all writes have completed

EXPERT LEVEL for efficiency

20
New cards

atomic instructions

an instruction modify some memory location so all memory accesses are strictly before or after

operations are performed as a single invisible step, so no overlap

21
New cards

test-and-set instruction

set a value to 1 and returns its previous value, atomic instruction

22
New cards

compare-and-swap

set a value in memory and return whether it had expected value, only modify value if its the same

23
New cards

critical sections

parts of code changing shared data, we want all access to data to be in a critical section to for sequential access

24
New cards

pthread_mutex_t

opaque data structure, must not be copied

25
New cards

create new pthread_mutex_t m

pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;

26
New cards

int pthread_mutex_init (pthread_mutex_t mut, pthread_mutexattr_t attr);

mut -> pthread_mutex_t lock

attr -> use NULL for default options

27
New cards

int pthread_mutex_destroy (pthread_mutex_t *mut)

destroy a lock (typically at end of program)

28
New cards

int pthread_mutex_lock (pthread_mutex_t *mut)

acquire the mutex lock, if another thread has mutex, block until that thread releases, then we can access critical section

29
New cards

int pthread_mutex_unlock (pthread_mutex_t *mut)

release mutex, only thread that has mutex can unlock it

if any threads were waiting, activate the one waiting the longest

30
New cards

condition variable

block a thread until a condition is met

31
New cards

pthread_cond_t

opaque data structure, shouldn't be copied

always associated with a mutex

32
New cards

int pthread_cond_init (pthread_cond_t cond, pthread_condattr_t attr)

create condition pthread, attr is NULL for default values

33
New cards

int pthread_cond_destroy (pthread_cond_t *cond);

destroy condition lock

34
New cards

int pthread_cond_wait (pthread_cond_t cond, pthread_mutex_t mut);

we must currently hold mut, block calling thread after unlocking mut

block until condition is true

35
New cards

int pthread_cond_signal (pthread_cond_t *cond);

tells one thread waiting for condition to proceed

36
New cards

int pthread_cond_broadcast (pthread_cond_t *cond);

tells all threads waiting for condition to proceed

37
New cards

when does a thread end?

when its starting function returns, then we detach it

OR when it calls pthread_exit()

38
New cards

what happens when exit() is called in a thread?

terminates all threads

39
New cards

int pthread_kill (pthread_t target, int signal_number);

sends a signal to specified thread

40
New cards

how to handle blocking signals with multiple threads?

use pthread_sigmask() instead of sigprocmask()

block signal in creator thread, create new thread, then unblock signal to let new thread inherit disposition

41
New cards

deadlock

situtation that can arise with multiple communicating processes where no process can make progress

42
New cards

necessary conditions for deadlock

1) mutual exclusion

2) hold and wait - block waiting for a resource while holding another

3) no preemption - cant force a thread to release a resource

4) circular wait - each thread is waiting for a resource held by another in a cycle

43
New cards

to avoid a deadlock

ensure at least one condition is not satisfied

44
New cards

semaphores

non-negative integer that we either increment or decrement

45
New cards

increment / post

increases value of semaphore by 1

if semaphore was 0, wakes up 1 thread

46
New cards

decrement / wait

decreases value of semaphore by 1

if semaphore is zero, blocks until another thread calls post

47
New cards

how is mutex a semaphore?

starting value 1

lock -> wait

unlock -> post

48
New cards

process group

a set of one of more processes identified by PID

49
New cards

process group leader

if process is running with the same PID as PGID

50
New cards

session

one or more process groups, usually associated with login session or a terminal, identified by session ID

51
New cards

network communication

inter-process conmmunication, processes may be hosted on different computers

52
New cards

link

direct connection between two devices/hosts

53
New cards

network

collection of hosts that can communicate, directly or indirectly

54
New cards

internetwork

two or more connected networks

55
New cards

circuit switching

communication resources are dedicated to a particular session, guaranteed quality but consumes a lot of bandwidth

56
New cards

packet switching

messages come in discrete units, not a continuous stream (packets, frames) more efficient and less expensive, messages may have to be split up for travel

57
New cards

latency

length of time between transmission and receipt

58
New cards

throughput

how many bits we can transmit per second

59
New cards

application layer

send messages among different hosts

60
New cards

network layer

routes messages between indirectly connected hosts, find a route to enable message arrival

61
New cards

link layer

transmits messages between directly connected hosts

62
New cards

internet protocol (ip)

best-effort, packet-switched, connection-less protocol

5 layer practical networking framework focusing on data being transmitted

63
New cards

OSI

7 layer conceptual framework, each layer has clearly defined function and works independently of otheres

64
New cards

what are the five layers of internet protocol?

application, transport, network, data link, physical

65
New cards

what are the three layers in osi that correspond to ip's application layer?

session, presentation, application

66
New cards

best effort

no guarantee data is effectively delivered or that delivery meets quality of service

67
New cards

how many bits does an IPv4 address have?

32 bits

68
New cards

how many bits does an IPv6 address have?

128 bits

69
New cards

ip addresses are used

to help routing from indirectly connected hosts

70
New cards

subnet mask

how many bits belong to the network

192.168.1.0/24 -> first 24 bits are network, last 8 are host

71
New cards

what are the two methods of the transport layer in ip?

udp, tcp

72
New cards

udp (user datagram protocol)

no guarantee packets will arrive or be in correct order but very fast

73
New cards

tcp (transmission control protocol)

provides reliable, ordered, and error-checked delivery of a stream of packets on the internet, need to establish reliable TCP connection before sending data

74
New cards

domain name service (DNS)

internet directory service that allows devices and services to be named and discoverable

75
New cards

domain

sequence of names separated by dots, each name is controlled by someone who assigns subdomains

76
New cards

sockets

api for network communication (part of posix library)

77
New cards

int sock(int domain, int socket_type, int protocol);

domain -> network we are using

socket_type -> what sort of socket are we creating

protocol -> additional flags

78
New cards

domain in socket

AF_INET -> v4

AF_INET6 -> v6

79
New cards

socket type in socket function

SOCK_DGRAM -> datagrams (connectionless, unreliable)

SOCK_STREAM -> streaming connection (connection-oriented, reliable)

80
New cards

connectionless communication

data transmission method using data packets by addressing data packet to new destination

81
New cards

connection-oriented communication

establish a connection before transferring any data

82
New cards

socket returns

file descriptor used to reference socket on success

-1 and sets errno on failure

83
New cards

int connect (int socketfd, struct sockaddr *remote_addr, socklen_t remote_addr_len);

establish a connection to a remote host accepting incoming connection

socketfd -> socket we are using to connect

remote_addr ->address(host:port) of remote end

remote_addr_len -> sizeof(remote_addr)

84
New cards

connect returns

0 on success, -1 on failure

85
New cards

bind()

associate socket with port number

86
New cards

listen()

put socket into passive mode and wait for incoming connections

87
New cards

connect()

establish connection with running socket

88
New cards

datagram endpoint

send and recieve datagram packets

89
New cards

listening socket

used for connection-oriented sockets (TCP), wait for incoming connection (establish path)

90
New cards

connection socket

one end of connection

91
New cards

nimd program structure

create listening socket in openListener and return connection from client

create connection socket using accept()

send data using send() function

92
New cards

signals

send asynchronous messages to processes

93
New cards

disposition for a signal

what happens when that signal is recieved

94
New cards

possible dispositions

ignore, terminate, stop, continue, run signal handler

95
New cards

how do dispositions carry over from fork()

inherited in child process

96
New cards

how are dispositions handled using exec()

preserved in running program except for handler functions

97
New cards

kill

sends SIGTERM to specified process

98
New cards

kill - [NAME]

sends SIGNAME to specified process

99
New cards

kill -KILL

sends SIGKILL to specified process

100
New cards

int sigaction (int signumber, const struct sigaction new, struct sigaction old);

signal type, new disposition, old disposition is written to old