Course: CPE 473: Operating Systems
Institution: Jordan University of Science and Technology
Department: Computer Engineering
In this assignment, you will implement a multi-threaded program in C/C++ to:
- Check for Prime Numbers and Palindrome Numbers in a given range.
- Identify numbers that are both Prime and Palindrome (Palindromic Primes).
Your program will create T
worker threads to divide the range and process numbers. Each thread will handle a part of the range and report its results.
The input file (in.txt
) contains:
- Two integers:
rangeStart
andrangeEnd
, representing the range of numbers (inclusive).
The program will accept the number of threads (T
) as a command-line argument.
- Results from each thread (to be printed on STDOUT):
- Thread ID
- Start and end of the range it is processing
- Summary (on STDOUT):
- Total numbers processed.
- Counts for:
- Prime numbers
- Palindrome numbers
- Palindromic Prime numbers
- Results of prime numbers (to be saved in out.txt):
- Lists of Prime numbers, Palindrome numbers, and Palindromic Primes.
-
Two Versions of the Program:
- Thread-unsafe version: No synchronization mechanisms.
- Thread-safe version: Proper synchronization for shared resources.
-
Global Variables:
numOfPrimes
: Total number of prime numbers.numOfPalindromes
: Total number of palindrome numbers.numOfPalindromicPrimes
: Total number of palindromic prime numbers.TotalNums
: Total numbers processed.- Lists:
PrimeList
: All prime numbers.PalindromeList
: All palindrome numbers.PalindromicPrimesList
: All palindromic primes.
-
Each thread must:
- Print its ID and range at the start.
- Update shared variables and lists.
-
Command-line Argument (
T
):- Specify the number of threads.
- Example:
./a.out 4
-
Environment:
- OS: Linux (Ubuntu).
- Compiler: g++.
- Thread Library: pthread.
-
Source codes: Unsafe version, Safe version
-
Report: Report.pdf