Description
Multi-Threading
Programming
Example – Hello Thread!
hello_thread.c
Output
vvvvvvvvdddv
x
<pthread.h> library info
Ref:
Tools for showing threads
• NCTU Workstation > top
(THR means the num of threads under the process)
Tools for showing threads
-
Ubuntu -> sudo apt-get install htop
-
-
– – press <F2> to enter htop setup menu.
-
-
-
– – Choose “Display option” under “Setup” column, and toggle on “Three view” and “Show custom thread names” options.
-
-
-
– – Presss <F10> to exit the setup.
-
Tools for showing threads
-
Mac -> Enter the terminal > top
Problem: Sum Checker-input
-
Input file: test.txt (it contains a 2D array.) Ex. (-1 means the (x=0 or y=0) of the 2D array. )
Problem: Sum Checker-rules
-
Given a 9×9 2D-array and each item of the array must be the digits 1 to 9.
-
Sum of each row, column, and each of the nine sub-grids must be the same and every digits only show once.
-
Hint:
-
-
A thread to check that each sum of the rows.
-
-
-
A thread to check that each sum of the cols.
-
-
-
Nine threads to check each sum of the 3×3 sub-grids.
-
Row
s
Colum
ns
3×3
subgrids
Checker-Output
Code output
Check num of the threads under your process
Problem: Sum Checker- Time
Command: time ./exe
Multi-thread Single thread
V.S
Requirements
-
You can write codes in C/C++.
-
You need to hand in one single-thread version and the other multi-thread version. Put all of *.c or *.cpp source files and OS_hw2_report.pdf into same compressed file. The type of compressed file must be
“studentID_hw2.zip” (ex. 010101_hw2.zip)
-
Use NCTU workstation as your environment
Deadline: 2018/10/28(日) PM 11:59
• Filename format sample
Grade
-
-
Total score: 100 pts: COPY WILL GET A 0 POINT!
-
-
Input sample +10 pts
-
Two testing data + 10 pts (5 pts for each)
-
multithreading +40 pts
( report Q3: speed up= Ts/Tm ;
Ts:Time of single thread code ; Tm:Time of multi-thread code)
-
OS report (format OS_report.pdf) + 40 pts
-
Incorrect filename format will get -5 pts
-
-
Incorrect output format will get -5 pts
-
DELAYED SUBMISSION WILL GET 0 POINT!