Question

Write a C++ program to demonstrate thread synchronization. Your main function should first create a file...

Write a C++ program to demonstrate thread synchronization. Your main function should first create a file called synch.txt. Then it will create two separate threads, Thread-A and Thread-B. Both threads will open synch.txt and write to it. Thread-A will write the numbers 1 - 26 twenty times in nested for loops then exit. In other words, print 1 - 26 over and over again on separate lines for at least 20 times. Thread-B will write the letters A - Z twenty times in nested for loops then exit. You must use a mutex lock to control synchronization between the two threads. When the program is complete, the synch.txt file should look like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ..... 20x A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ... 20x

Homework Answers

Answer #1

OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
C Programming I am trying to also print the frequency and the occurrence of an input...
C Programming I am trying to also print the frequency and the occurrence of an input text file. I got the occurrence to but cant get the frequency. Formula for frequency is "Occurrence / total input count", this is the percentage of occurrence. Can someone please help me to get the frequency to work. Code: int freq[26] = {0}; fgets(input1, 10000, (FILE*)MyFile); for(i=0; i< strlen(input); i++) { freq[input[i]-'a']++; count++; } printf("Text count = %d", count); printf("\n"); printf("Frequency of plain text\n");...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
QUESTION 14 Given: Net Filtration Pressure = (PC – PIF) – (πC – πIF) IF: capillary...
QUESTION 14 Given: Net Filtration Pressure = (PC – PIF) – (πC – πIF) IF: capillary colloid osmotic pressure = +22 mmHg : interstitial fluid colloid osmotic pressure = +4 mmHg : capillary hydrostatic pressure = +30 mmHg : interstitial fluid hydrostatic pressure = -2 mmHg THEN, the Net Filtration Pressure is _____________ and there is _______________ across the capillary wall. a. -14 mmHg, Net Reabsorption b. 10 mmHg, Net Filtration c. None of the answers given here are correct...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
Please match the following regions or parts of the brain with their function(s) (some parts are...
Please match the following regions or parts of the brain with their function(s) (some parts are used more than once). 16.__ The auditory cortex, where sounds are made conscious, is located here 17.__ Contains the respiratory centers 18.__ The visual cortex is located here 29-40. Match each cranial nerve with its function/correct description. 29.___Nerve that carries sensory fibers (taste and touch) from the posterior 1/2 of the tongue to the brain 30.___Nerve that carries motor fibers from the brain to...
Match the correct terminology to the scenario. (match the letters with the correct number) TERMINOLOGY (LETTERS):...
Match the correct terminology to the scenario. (match the letters with the correct number) TERMINOLOGY (LETTERS): A-Diversity Jurisdiction B-Dodd Frank C-Due Process (5th Amendment) D-Subject Matter Jurisdiction E- Establishment Clause (1st Amendment) F-Foreign Corrupt Practices G- Invasion of Privacy (appropriation of identity) H- Attractive Nuisance I- Special Damages (Compensatory) J- Commercial Speech (1st Amendment) K- Dormant Commerce Clause L- Legitimate Government Interest M-4th Amendment N- Madison V. Marbury O- Rule of Four P- Voir Dire Q- Articles of Confederation R-14th...
Select the letter (a, b, c,d, e, f) with the most appropriate answer 1) The first...
Select the letter (a, b, c,d, e, f) with the most appropriate answer 1) The first step is to: A) Take care of the worst looking victim first B) Start where you stand C) Stop, look, listen and think D) Conduct voice triage Ans:........ 2) Triage which victim first? A) The worst looking victim B) The worst sounding victim C) The closest victim D) The youngest victim Ans:........ 3) An example of check mental status is: A) Do I remember...
1. What is an ISP (Integrated Service Provider) for supply chains? (1 point) A. A consultant...
1. What is an ISP (Integrated Service Provider) for supply chains? (1 point) A. A consultant agency which integrates the supply chain for companies B. A 2 PL or a 3PL, but not a 4PL C. A company supplying transportation and warehousing services D. A logistics service company specialized in suppling VAS (value added services) 2. What characterizes a 4 PL? (1 point) A. They are non-asset based and provides integrated services primarily supplied by asset based providers, for example...