Posts

Showing posts from July, 2024

CST 334 Week 6 Journal Entry

Image
Semaphores Semaphores are synchronization primitives that can help manage shared resources. They are variables associated with an underlying counter that can be any integer. Atomic operations can be applied to a semaphore, which will ensure that threads access shared resources in a controlled and orderly manner.  Two functions can be used to implement a semaphore: sem_wait and sem_post. The function sem_wait() is called before a critical section of code and decrements the value of a semaphore. If the semaphore is positive, then shared resources are available, and a thread may have access to the critical section. In this case, the semaphore's value is decremented, and the function returns. If it is zero or negative, shared resources are unavailable, and the thread is blocked from the critical section. In this case, the thread has to wait until the semaphore value is positive to access the critical section.  The function sem_post() is called at the end of a critical section of code.

CST 334 Week 5 Journal Entry

Image
Concurrency This week, we learned about the importance of threads in a process. A thread is a point of execution for a single running process. When a program is running, it can have more than one thread running at a time. Each thread has its own stack to store local variables and function calls, but resources such as code and heap can be shared from the program. Threads are like separate processes, except they share the same address space. When we switch between threads, thread control blocks are used to store and restore the state of the thread. This is a quick action as the threads share the same address space. Threads can help run tasks parallel to each other on different CPUs or run concurrently on the same CPU.  When more than one thread runs concurrently, it is important to take some precautions to avoid a race condition. A race condition occurs when threads in a program access critical sections of code concurrently. This can lead to the program being indeterminate, which is when

CST 334 Week 4 Journal Entry

Image
Virtual Memory Virtual memory provides abstraction so that processes run with the illusion that they have their own private memory address. To do this, the OS uses a virtual-to-physical address mapping using a page table. Processes are given a virtual address to run on, and that virtual address is mapped to a physical address. The process uses the virtual address to run, and the physical address is kept hidden from the process but helps the process execute.  To map from a virtual address to its physical address, we need to complete an address translation. Virtual addresses consist of a virtual page number(VPN) concatenated with offset bits. In a page table, VPN is the index for a page table entry(PTE). To find the physical address, we can use the VPN of a virtual memory address to find the PTE of the virtual address and use the right-most bits of the PTE to identify the Page Frame Number. We can concatenate the PFN with the offset bits to obtain our physical address.   Let’s assume we

CST 334 Week 3 Journal Entry

Image
 Intro to Memory Virtualization Memory virtualization provides the illusion that each process has a large private address space for a program to run. Virtualizing memory is done by building large address spaces for multiple running programs on a single physical memory. Each space has a virtual address that contains the program's instructions and data, as well as a heap, a stack, and free space. The OS takes the virtual address reference and turns it into a physical address for the program to run on. The OS does this with 3 goals in mind:  Transparency: Each process is not aware that memory is shared. Efficiency: minimize fragmentation and not waste memory resources Protection: Onc process cannot corrupt another (isolation) During the process, memory can be allocated on the heap or stack. Memory is allocated on the stack automatically for variables. Memory on the heap can be allocated by using the malloc() and freed using free(). It is important that once memory is allocated on the

CST 334 Week 2 Journal Entry

Image
 Processes This week in CST 334, we learned about processes. A process is a running program. It consists of an address space containing instruction and data and registers containing a program counter and stack pointer. Before a process starts running, it is considered a program. The code and data from the program are loaded into memory as well as the address space. Memory is then allocated on the run-time stack to hold local variables, function parameters, and return addresses. Next, memory is allocated to the program's heap. After some other initialization tasks, the program is ready to be executed, turning the program into a process. Once started, a process can be in three states: Ready, Running, or Blocked. When a process is ready, it has not been executed on the operating system, but the necessary steps to perform the process have been completed. When a process is running, the processor executes the instruction from the process. When a process is blocked, it is not ready to run