Posts

Showing posts from July, 2024

CST 334 Week 6

Image
  WELCOME TO WEEK 6 Learning Journal This week I learned about semaphores, which are objects with an integer value that one can manipulate with the functions `sem_wait()` and `sem_post()`. It is also important to know that the initial value of the semaphore determines the way it will behave. To initialize a semaphore, one must use `sem_init()` which has three parameters, with the third one being the initial value. Depending on that value, the semaphore will behave differently. For example, if its value is 1, it behaves like a lock. However, if you want the semaphore to act like a condition variable, the initial value should be 0. This can be used, for instance, when you want semaphores for ordering. An example provided in the text is if a thread wishes to wait for a list to become non-empty so it can delete an element from it. This is often where a thread waits while another signals that it is done with what it was doing.  We also learned about concurrency problems that can either be d

CST 334 Week 5

Image
  WELCOME TO WEEK 5 Learning Journal This week we learned about concurrency and its role in running programs. Concurrency is achieved through an abstraction called a thread. A thread is similar to a separate process but shares the same address space and has access to the same data. Each thread has its own stack, stack pointer (SP), and program counter (PC). The state of each thread in a process is stored in what is called a thread control block (TCB). Although threads share some data, each thread runs independently. However, there is a problem. When we run code, even on a single processor, we don't necessarily get the desired result each time. This is due to uncontrolled scheduling; a timer interrupt can go off and create a context switch, which can lead to incorrect results. This is called a race condition, where the results depend on the timing of the code's execution, giving us an indeterminate result. This can also happen with multiple threads executing code in what is call

CST 334 Week 4

Image
  WELCOME TO WEEK 4 Learning Journal This week we learned about Paging, a different approach that chops up space into fixed-sized pieces. This approach divides the address space into fixed-sized units, which we call a page. The physical memory in the fixed-sized slots is called page frames. These page frames contain a single virtual memory page. There are two problems with this approach: sometimes it can run slow, and it can also take up a lot of memory. A solution to these problems is the use of TLBs (Translation Lookaside Buffers), which create faster address translations. TLBs can be managed by both the OS and the hardware. There are TLB misses and TLB hits. When there is a TLB hit, it means that the TLB holds the translation. However, when there is a TLB miss, the CPU does not find the translation in the TLB. We were also introduced to solutions to the problem of page tables being too big, consuming a lot of memory. Some of the approaches are the hybrid approach (which consists of

CST 334 Week 3

Image
  WELCOME TO WEEK 3 Learning Journal This week I learned a lot of new things that focused on the virtualization of memory. Among the things I learned was the abstraction called address space, which is the running program's view of the memory in the system. The address space for each process contains the code of the program, the heap which is used to dynamically allocate memory, and the stack, which can allocate local variables. Programs use a virtual address, and the OS, with the support of the hardware, ensures the load goes to the appropriate physical address. There are a few goals that must be considered for the virtualization of memory. These goals are transparency, efficiency, and protection. Protection also enables isolation, which is very important to maintain among the processes. It is also important that when allocating memory, it is done correctly. For example, using the malloc( )  call with the appropriate arguments and ensuring we request enough memory. When we are done

CST 334 Week 2

Image
  WELCOME TO WEEK 2 Learning Journal Last week, we were introduced to the functions of Operating Systems, such as providing abstraction and being a resource manager. This week, we went deeper into the topic. I learned about what abstraction is, which is the process of a running program. The program itself is something that sits on the disk with many instructions, waiting to start and become a process. Virtualization is then accomplished when there are multiple processes running. In order for the OS to create the illusion of virtualizing the CPU, it needs two things. First, low-level machinery, which is the mechanism, and second, some high-level intelligence. I also learned about the creation of a process. As mentioned before, the program sits on the disk with code and static data, which is then loaded into the process inside the memory. Then memory is allocated for the program's stack. The OS will also initialize the stack with arguments for the main() function. Next, the OS alloca