Subject Computer Science Operating Systems

Question

Write a program (in C, or Java, or C++, or C#) that creates three new threads (besides the already existing main thread) and synchronizes them in such a way that each thread displays it's thread id in turn for 5 iterations. The output of the program should look like this:

Thread 1 - iteration no. 1

Thread 2 - iteration no. 1

Thread 3 - iteration no. 1

Thread 1 - iteration no. 2

Thread 2 - iteration no. 2

Thread 3 - iteration no. 2

Thread 1 - iteration no. 3

Thread 2 - iteration no. 3

Thread 3 - iteration no. 3

Thread 1 - iteration no. 4

Thread 2 - iteration no. 4

Thread 3 - iteration no. 4

Thread 1 - iteration no. 5

Thread 2 - iteration no. 5

Thread 3 - iteration no. 5

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class Counter implements Runnable
{
    protected int count = 5;

    /*
    * the counter is incremented when
    * the class is instantiated and assigns unique ID to each
    * instance; the id is displayed in run() method
    */
    private static int task_count = 1;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$20.00

or free if you
register a new account!

Assisting Tutor

Related Homework Solutions

Processes Behavior Under Windows OS Dealt by Task Manager
Homework Solution
$60.00
Process
Task Manager
Taskmgr.exe
Windows
Applications
Ctrl
Alt
Del
Esc
Status
Not Responding
Switch To
PID
CPU
Running
Tab
Memory
Priority
System
Idle
Real-Time
Performance
Usage
History
Commit Charge
Total
Limit
Peak
Kernel
C Shell Simulator
Homework Solution
$50.00
C
Computer
Science
Shell
Simulator
Background
Execution
Fork
Operating
Systems
Process
Child
Windows OS Environment & Process Explorer Utility Assignment
Homework Solution
$75.00
Windows
OS
Process
Explorer
Task
Manager
CPU
Usage
History
Graph
Memory
I/O
Utilization
Thread
Process
State
Id
Priority
Scheduler
Parent
Child
CSwitch
Delta
Virtual
Size
Fault
Path
Image
Working
Set
Get help from a qualified tutor
Live Chats