Using Semaphores to Manage a Shared File/Linux, C or C++ (ID:886)
Project Creator: |
XXLAKERSXX
FC Member For 6834 Days
Credits 20 Completed Proj. Num. 0 / 1 Total payment USD Avg Daily Online 0.00 h (From 21/5/2007) Available on MSN/Skype No Last Login // Peers Rating 0.00% ![]() ![]() ![]() |
---|---|
Budget: | Less than 250 |
Created: | 6/10/2006 12:22:24 PM EST |
Bidding Ends: | 6/12/2006 12:22:24 PM EST ( Expired ) |
Development Cycle: | 4 Days |
Bid Count: | 1
|
Average Bid: | 100.00 |
Project Description:
You shall implement a program which uses semaphores to manage a shared file You shall create a process. This process shall: Create a file, A.txt, in the current directory (cwd). Write it's pid (followed by a Carriage Return and Newline) in the file. Close the file A.txt Create a semaphore SemA for the file A.txt. Create 5 threads. Each thread shall have a unique identifier which you establish when you create the thread. Use the POSIX version of threads (i.e. pthread_create()) Block/wait for all five threads to complete their work Destroy the semaphore, then exit Each thread shall perform the following: Once every second, open the file A.txt and write your unique thread identifier of that thread (followed by a Carriage Return and Newline) Close the file A.txt Repeat 9 more times (so it writes to the file 10 times each), then exit You will need to use the following POSIX system calls for creating and managing the semaphores with: sem_init(), sem_wait(), sem_post(), and sem_destroy() Each child process shall use sem_wait on SemA when it opens A.txt and sem_post() on SemA when it closes A.txt. You will ensure that this implementation meets the critical section requirements, take precautions to avoid deadlock. You may use any additional data structures and algorithms as necessary. If you need to share a variable, you may use additional semaphores, pipe(s), shared memory, a file, or any other IPC mechanism you wish to use. NOTE - you might even consider using the Dining Philosophers problem solution. Your program shall be written such that it compiles and executes cleanly when using the cc, gcc, CC, or g++ compiler You shall create a sub-directory named "a2" in your home directory. In it, you shall place your source file(s), your header file, your Makefile, and a README file. The README file will include enough information for me to read in order to know who you are, what the program does, any special compile/operating instructions, and any features which you don't think operate properly or point out additional features you may have implemented. Your source files SHALL CONTAIN sufficient comments for making the source easy to read. Points will be taken off for poorly (or non) commented source. Name the executable "sem". Create ~/a2 by hand. Create source files, an include file, a Makefile, and a README file. Put them into ~/a2. The Makefile shall create an executable named "sem" in this same directory (~/a2). Here is a nice overview of threads The system call "system()" will NOT be allowed This project must be complete by June 14, 2006. |
|
Job Type | C/C++ |
Attached Files: | N/A |