CSCE313 Texas A & M University C++ Program PA5 Development Project Please write a c++ code and provide comments for easier understanding. Complete everything that is required in the PDF document to be submitted. the pptx is for your reference. I can provide a video for better understanding as well. CSCE 313
Wei Zhang
Programming
Assignment 6
PA3 Review
w worker threads
DATA
REP
Data channel 1
DATA
REP
Data channel 2
DATA
REP
DATA
REP
Data
Server
…
DATA
REP
Data channel w
DATA
REP
• Each worker spends most of the time waiting for data
server responses (inter-process delay)
–Assume 10 sec communication delay
–1 worker can do 0.1 req/sec, 10 workers can do 1
req/sec
PA3 Review
• Each worker watches one data channel for response
–Blocking I/O: Wait till data is ready
–Low CPU utilization as most workers are waiting
• Workers are constantly switched on and off CPU
–High context switching cost
–Given x CPU cores, is there any reason to have more
than x workers?
PA6
• PA6 Method: Use one single event handler thread to
deal with the I/O for all data channels
–Avoid context switching
–Non-blocking I/O: After issuing a request, switches
to other tasks without waiting for response
–Event driven: When data from data channel i is
ready, signal an event
Event handler
DATA
REP
Data channel 1
DATA
REP
Data channel 2
DATA
REP
DATA
REP
…
DATA
REP
Data channel w
DATA
REP
Data
Server
What We Did in PA3
• In PA3, we called cwrite() immediately followed by a
cread() – this made a thread always until data came
back from server.
• In PA6, we will change that by issuing a bunch of
cwrite()’s and then a bunch of cread()’s
client
Experienced
delay
server
Random delay
inserted by server
PA6
client
server
Initialization: Issue w requests to make
all worker channels busy
w initial requests
keep issuing
requests till 3n
After receiving response from channel i,
issue another request to the same
channel and make it busy again
When receiving response from channel
i, how do I know the corresponding
request?
– Maintain an array of w requests, one
for each channel that remembers the
last request sent through
Event Handler
• Use select() to listen to w worker channels
file descriptor sets to check
int select(int nfds,
fd_set *readfds,
# of fds that are ready
fd_set *writefds,
fd_set *exceptfds,
struct timeval *timeout);
Set these to
NULL, because
we only care
about readfds
block for timeout long, or (NULL) indefinitely
• nfds is the highest-numbered file descriptor in any of
the three sets, plus 1, not # of fds
• We only care about read operations, set writefds,
exceptfds to NULL
fd_set
•
•
•
•
•
A set of file descriptors
FD_ZERO(): Initialize
FD_SET(): Add a fd to set
FD_ISSET(): Check if a fd is ready
select() will modify the fd_set data structure, so
needs to provide a new copy every time
• When select() returns, how to test which data
channels are ready?
–Use FD_ISSET() to test each file descriptor
Purchase answer to see full
attachment
Consider the following information, and answer the question below. China and England are international trade…
The CPA is involved in many aspects of accounting and business. Let's discuss some other…
For your initial post, share your earliest memory of a laser. Compare and contrast your…
2. The Ajax Co. just decided to save $1,500 a month for the next five…
How to make an insertion sort to sort an array of c strings using the…
Assume the following Keynesian income-expenditure two-sector model: AD = Cp + Ip Cp = Co…