random point coordinates between z = (-10 → 10) and y = (-2 -→ 2) and store these coordinates in seperate text files in respect to the cartesian quadrants they are located in: NW NE - 10 10 SW SE -2 Your program must use threads. The number of threads T must be specified as a command line argument (hint: use a dynamic thread array in your program). Each thread is responsible from generating random N (x, y) points between the ranges mentioned above; therefore total number of points will be T • N. N must also be defined as a command line argument. Each of these points will fall in the range of a cartesian quadrant (NE, NW, SW, SE). After randomly generating cach point, each thread must find out which cartesian quadrant the point falls into, store its coordinate in seperate text files (nw.txt, ne.txt, etc) line by line and keep count of points in each quadrant. Also, there will be some points that fall over the X or Y axes; coordinates of such points must be stored in a seperate text file (xy.txt) and use a seperate counter as well. Since we have T threads and only 5 files, the threads must be careful when writing into these files. Instead

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Outputs of your program:
ˆ 5 text files, each containing point coordinates for a different quadrant or axes,
ˆ A summary line on standard output.
1
You will get points from;
ˆ Proper use of command line arguments,
ˆ Proper use of threads,
ˆ Proper use of semaphores and definitions of critical regions,
ˆ Proper handling of files,
ˆ Proper implementation of the requested problem.
Remember;
ˆ No teamworking is allowed.
ˆ You may study from other sources but you are strictly forbidden from copying and/or modifying
from them.
Different sample runs of this program is as follows. Do note how the program responds with missing
arguments. Also do note how the number of lines in each text file corresponds with the program output
and total is reported as M ∗ N.
--Sample Run 1--
$ ./hw
Usage: ./hw NRTHREAD POINTSPERTHREAD
--Sample Run 2--
$ ./hw 4
Usage: ./hw NRTHREAD POINTSPERTHREAD
--Sample Run 3--
$ ./hw 4 20000
NW: 19911 NE: 19969 SW: 19858 SE: 19800 XY: 462
$ wc -l ne.txt nw.txt se.txt sw.txt xy.txt
19969 ne.txt
19911 nw.txt
19800 se.txt
19858 sw.txt
462 xy.txt
80000 total
--Sample Run 4--
$ ./hw 8 15000
NW: 29761 NE: 29856 SW: 30069 SE: 29678 XY: 636
$ wc -l ne.txt nw.txt se.txt sw.txt xy.txt
29856 ne.txt
29761 nw.txt
29678 se.txt
30069 sw.txt
636 xy.txt
120000 total
And this is a sample from a generated text file:
$ cat nw.txt
-5.820000 1.090000
-0.300000 0.410000
-6.910000 0.270000
[. . .]

In this homework, you are expected to write a C program which demonstrates your ability to use threads
and semaphores. Basically, you are expected to implement a program which will repeatedly generate
random point coordinates between r = (-10 → 10) and y = (-2 → 2) and store these coordinates in
seperate text files in respect to the cartesian quadrants they are located in:
NW
2
NE
- 10
10
SW
SE
-2
Your program must use threads. The number of threads T must be specified as a command line argument
(hint: use a dynamic thread array in your program). Each thread is responsible from generating random
N (x, y) points between the ranges mentioned above; therefore total number of points will be T » N.
N must also be defined as a command line argument. Each of these points will fall in the range of a
cartesian quadrant (NE, NW, SW, SE). After randomly generating each point, each thread must find out
which cartesian quadrant the point falls into, store its coordinate in seperate text files (nw.txt, ne.txt,
etc) line by line and keep count of points in each quadrant. Also, there will be some points that fall
over the X or Y axes; coordinates of such points must be stored in a seperate text file (xy.txt) and use a
seperate counter as well.
Since we have T threads and only 5 files, the threads must be careful when writing into these files. Instead
of storing point coordinates in memory, each thread must store them in files immediately when they have
been created. Since the threads will be constantly writing into these files one-by-one and need access
to all files at all times, you can not simply open them once and keep them open for the duration of the
program; you must open, write into and immediately close them instead. In order to prevent incorrect
access to these files by your threads, you must use semaphores and define critical regions to make sure
each file is in use by only one thread at a time.
Inputs for your program:
• Number of threads as a command line parameter,
• Number of points per thread as a command line parameter.
Transcribed Image Text:In this homework, you are expected to write a C program which demonstrates your ability to use threads and semaphores. Basically, you are expected to implement a program which will repeatedly generate random point coordinates between r = (-10 → 10) and y = (-2 → 2) and store these coordinates in seperate text files in respect to the cartesian quadrants they are located in: NW 2 NE - 10 10 SW SE -2 Your program must use threads. The number of threads T must be specified as a command line argument (hint: use a dynamic thread array in your program). Each thread is responsible from generating random N (x, y) points between the ranges mentioned above; therefore total number of points will be T » N. N must also be defined as a command line argument. Each of these points will fall in the range of a cartesian quadrant (NE, NW, SW, SE). After randomly generating each point, each thread must find out which cartesian quadrant the point falls into, store its coordinate in seperate text files (nw.txt, ne.txt, etc) line by line and keep count of points in each quadrant. Also, there will be some points that fall over the X or Y axes; coordinates of such points must be stored in a seperate text file (xy.txt) and use a seperate counter as well. Since we have T threads and only 5 files, the threads must be careful when writing into these files. Instead of storing point coordinates in memory, each thread must store them in files immediately when they have been created. Since the threads will be constantly writing into these files one-by-one and need access to all files at all times, you can not simply open them once and keep them open for the duration of the program; you must open, write into and immediately close them instead. In order to prevent incorrect access to these files by your threads, you must use semaphores and define critical regions to make sure each file is in use by only one thread at a time. Inputs for your program: • Number of threads as a command line parameter, • Number of points per thread as a command line parameter.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY