The output should look like: Child 1 PID: 113 Child 2 PID: 114 Beginning 3 Round
ID: 3595448 • Letter: T
Question
The output should look like:
Child 1 PID: 113
Child 2 PID: 114
Beginning 3 Rounds...
Fight
------------------------------
Round 1:
Child 1 throws Scissors!
Child 2 throws Rock!
COASTAL CAROLINA UN VERSITY Department of Computing Sciences CSCI 356- Operating Systems Homework Assignment #4 Due: Thursday, October 19, 2017 Name CCU ID: In this project, you will write a program that uses multiple threads (POSIX threads) to complete a task. Name your program (trpc.c) which will implement the rock, scissors, paper assignment from Homework #3 using p threads. The IPC mechanism that you will use is shared memory, since memory is easily shared between threads The main issue with using pthreads/shared memory over a fork/message passing solution is with the need for synchronization between the different threads. You should use a pthread condition variable to synchronize the parent and children threads. The output from this project should be identical to the last project (HW #3), except that the PID printed should be the thread identifier value (TID) You should also ensure that at the completion of the game, both child threads re-join parent thread before exiting. CSCI 356-Homework Assignment #4 Page 1Explanation / Answer
#include #include #include // Let us create a global variable to change it in threads int g = 0; // The function to be executed by all threads void *myThreadFun(void *vargp) { // Store the value argument passed to this thread int *myid = (int *)vargp; // Let us create a static variable to observe its changes static int s = 0; // Change static and global variables ++s; ++g; // Print the argument, static and global variables printf("Thread ID: %d, Static: %d, Global: %d ", *myid, ++s, ++g); } int main() { int i; pthread_t tid; // Let us create three threads for (i = 0; i < 3; i++) pthread_create(&tid, NULL, myThreadFun, (void *)i); pthread_exit(NULL); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.