CS 307 Operating SystemsFall 2019 Homework 3Memory Management API Phase 1In this project, you are going to implement a memory heap management API, and we willprovide a code for you to test your API. You are expected to create a shared memory, inorder to manage memory requests coming from multiple threads and grant or declinerequests based on free space available. You are also expected to manage all mutexesand semaphores for shared memory access.Program FlowThe main program, that we will give you, will call various functions in order to initialize,access, change and dump the memory. Also there will be an array of threads, an array ofsemaphores, a mutex, a memory server thread and a char array representing the memorygiven.The init() function that is also provided will initialize the memory array and the requestqueue and any related data structures. Afterwards it will start the memory server thread.After initialization, you are expected to start all of threads, which will run in a functioncalled thread_function(int id). This function will generate a random size and callthe my_malloc(int thread_id, int size) function, which you will alsoimplement. My_malloc will utilize the semaphores and mutex for synchronization ofaccess to shared data structures. The thread_function will wait for the answer and -ifmemory is granted- access the memory and set all the bytes allocated to it to charactervalue 1. The size of the memory will be randomly generated by thethread_function function.The memory server thread is expected to handle all requests for memory access. Allaccess requests will be appended to the shared queue. The server thread will read fromthis queue and depending on the size and availability will return an answer to therequesting thread. If there is enough space it should return the start address of the memory array. If there is not enough space it should return -1.For this phase of the assignment you will only maintain an index of the next availablespace. You are not expected to manage the memory allocations. The access will bebased on the index and the space remaining in the memory array. If the requested size issmaller than (memory_size index), then you should grant access.The thread which makes the request will be blocked till the memory server processes itsrequest If space is allocated: Gains access to the shared memory and set all the bytesallocated to it to character value 1 If space is not allocated: Prints an error message Thread ID: Not enoughmemory and exits.Expected Functionsmy_malloc(int thread_id, int size): This function should be called by a threadwith a size value no bigger than the memory itself. It will gain access to the shared queueand write the requesting thread_id and the amount.dump_memory(): This function is used to test memory allocation. It will print the entirecontents of the memory array onto the console.thread_function(int id): This function should run as a thread. The function shouldfirst create a random memory size. It will then call the my_malloc(id, size) functionand block until the memory request is handled by the memory server thread. Once thethread is unblocked by the memory server thread it will take appropriate action. Thememory server thread will store the value in a shared array called thread_message. Thevalue is -1 indicates there is no available memory, hence only an error message must beprinted. If the value is bigger than -1 then it will be interpreted as the starting point in thememory. It will set all the bytes allocated to it to character value 1. This entire processwill only run once, i.e. each thread will only make one memory request.server_function(): This thread will run until release_memory function is called. Itwill check the queue for the requests and depending on the memory size it should eithergrant or decline them. The answers to the requests will be written to thethread_message array and the requesting thread should be unblocked. It should returneither -1 for declining the request due to no available size, or the start_point of thememory location that will be allocated to the requesting thread.release_function(): This function will be called whenever the memory is no longerneeded. It will kill all the threads and deallocate all the data structures.thread_id: This value will be incrementally generated and passed to thethread_function as a parameter starting from 0 (zero), while the threads are being created.Shared Datachar memory[MEMORY_SIZE];pthread_mutex_t sharedLock;sem_t semlist[NUM_THREADS];int thread_message[NUM_THREADS];queue<node> memory_queue;Submission Guides:Solutions should be submitted in a zip archive, name your zip archive as:YourNameSurname_ID_hw3.zip and submit to SUcourse.Note that, your system time and SUcourse servers time may not be synchronized so donot wait the last minutes to submit your solution. Only the solutions in the SUcoursesystem will be graded. Other submissions, such as emailing to instructor or assistants,will not be graded.You will be graded on the correctness of your solution and your use of semaphores basedon the code we have sent. You shouldnt use unnecessary semaphores/mutexes, ormutexes to lock any actions. You should definitely avoid using other means of aligningyour threads. All of these dirty tricks may actually make your code look like it hassomehow finally started working but in fact they will cause your solution to be invalid!
CS307
[Solved] CS 307-Homework 3-Memory Management API Phase 1
$25
File Name: CS_307-Homework_3-Memory_Management_API__Phase_1.zip
File Size: 452.16 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.