01 Feb 2014
###Schema
###Relation algebra
###Some gotcha
- The use of
GROUP BY
followed by```having``` - duplicate vs. redundant
###Refs
###Feb 4 Class
30 Jan 2014
####Creating POSIX Threads
- returns a positive value indicating failure
####Structure pointer approach
P46
####Passing arguments to threads
- copy all arguments to the thread’s stack: isn’t supported in either POSIX or Win-32
- pass a pointer to local storage: should make sure this storage doesn’t go out of scope until the thread is finished with it
- pass a pointer to static or global storage: works only if one thread at a time is using the storage
- pass a pointer to dynamically allocated storage: works only if we can free the storage exactly when the thread is finished with it
####Threads terminate
- 2 ways:
- return from its first procedure(a value of type void*)
- call pthread_exit, supplying a void* argument
- difference:
- pthread_exit: terminates just the calling thread
- exit: terminates the entire process, including other threads in the process
####Deadlock conditions
- a thread can hold an item while waiting for another
- a thread cannot be forced toyield the items it is holding
- each container has a finite capacity
- a circular wait
####Semaphore
- binary semaphores
- counting semaphres
####Conditional variables
- P67: why not
if --writers == 0
- P70: Now when the waiting threads wake up, they will find the guard false….
####async-signal
- fork
- _exit
- open
- close
- read
- write
- sem_post
####Question
####Bear in mind
- it’s unsafe to make more than 1 call to pthread_join on any particular thread
- for each call to pthread_create there should be exactly one call to either pthread_join or pthread_detach.
- pthread_cleanup_push must match exactly with pthread_cleanup_pop
####Notes during db assignment
- It’s a common(if standard) approach to mask the signal you want to handle in the main thread, then create a handler thread, specifically unblocking the signal and waiting for the signal, to handle that signal.
- If you did not
pthread_detach
the thread, then you’ll have to pthread_join
the thread, or the resources allocated by the thread will not be collected.
- Signal is not that hard at all, just need to figure out the current state.
- If you cherish your life, stay away from
pthread_detach
!!!
28 Jan 2014
###lone
- multiplicity
-
- each name is mapped to at most one address
###Signature facts
- facts that apply to every member of a signature
###?lookup?
{n.^(b.addr) & Addr}
###?Why I have different result with the book?
pay attention to the address mapping change in the Book definition
###Some lessons
- start from a simple model, add more constraints as needed
27 Jan 2014
####Traps
- Invoking the kernel from user code
- Done by system calls
- Handled as part of the program that caused it
####Interrupts
- A request from an external device for a response from the processor.
- Handled independently of any user program
####Address space
- Stack
- going down
- going up
- Dynamic
- BSS(block started by symbol)
- Data
- Text
####Process Management
- fork()
- wait(&ReturnCode)
- exit(n)
-
- process calls exit- zombie state(PID and return value preserved)
- parent process calls wait- released(all traces disappear)
- parent terminates before the child
PID 1 inherits the children of terminated processes
####Exec(s)
- creates a new process to replace the program with a new one
- execl(name of file, name of program, command-line arguments terminating with 0)
- What if the size doesn’t match up?
The new process image will have different address spaces for text, data, BSS, Dynamic and Stack according to the new process.
####File Descriptors
####Pipe
int p[2];
pipe(p);
// p[0] for read
// p[1] for write
####Links
- Hard link: link system call or ln
- Symbol link: symlink system call or ln -s
####execve
execve(const char *path, char *const argv[], char*const envp[]);
- path is the path to the program
- argv
- The first element in argv is the name of the executed program(eg: last component of path, or whatever)
- The rest elements in args are argumentlist, terminated by NULL
- envp
- Environment pointer, null-terminated
- see environ(7)
####Bear in mind: some realations
- Every time you malloc, you have to free
- Every time you open, think about close
26 Jan 2014
##Week 1
###One Time Pad
Never use stream cipher key more than once!
- Network traffic: negotiate new key for every session
- Disk encryption: typically do not use a stream cipher