Question: Background Modern operating systems provide features for a process to use multiple threads for parallel operations. In the class, we have learned the concepts of

Background
Modern operating systems provide features for a process to use multiple threads for parallel
operations. In the class, we have learned the concepts of multithreading models. There are
various thread libraries. POSIX Pthreads and Java Threads are widely used for creating and
managing threads. The textbook (Threads, Chapter 4) gives examples of multithreaded
programs using these libraries.
Programming Language
CC++ or Java
Programming Task
In this project, you are required to create a program to simulate a web server handling jobs
from multiple clients. Your program should have N "client" threads and M "server" threads.
The client threads generate jobs to a job pool, and the server threads take jobs out of the pool
for processing. As the pool can only accommodate a limited number of jobs, adding and
removing jobs from the job pool must be synchronized. In specific, your program should satisfy
the following requirements:
(1) Your program should accept five input parameters to specify (a) the number of client
threads, (b) the number of server threads, (c) the number of job pool entries (i.e., the
number of jobs that can be accommodated in the pool),(d) the total number of jobs to be
generated, and (e) the job processing time (millisecond).
For example, the following command means that your program will create 2 client threads,
3 server threads, a job pool that can contain up to 10 jobs, generate 1000 jobs in total, and
each job takes 5 milliseconds for processing by a server thread.
$./serversim 231010005
(2) Similar to the producer-consumer problem, the job pool is a buffer that needs to be
maintained in your program and shared by all client and server threads. The job pool is an
array. Each entry of the job pool array can contain a job ID, which is an integer.
(3) Each client thread generates a job each time and adds the job into the job pool, if there is
space. Each job has a unique job ID. The generated job IDs must be strictly incrementing.
starting from 0(i.e.,0,1,2,3,4dots ). Your program needs to maintain a shared counter,
num_created_jobs, to track how many jobs have been created.
(4) Each server thread removes a job each time from the job pool for processing in the First-
In-First-Out (FIFO) order. Your program should maintain a counter,
num_processed jobs, to track how many jobs have been processed by the server threads.
To simulate the job processing time, the server thread should sleep for a period of time (in
milliseconds) as specified in the user's input argument.
(5) When a client thread or a server thread adds/removes a job to/from the job pool, it needs
to record the timestamp, the client or server thread ID, the index of the job pool entry that
accommodates this job, the job ID, into an event log file, named "service.log".
Each record of the log file should be formatted as follows:
log
 Background Modern operating systems provide features for a process to use

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!