QQuestionAnatomy and Physiology
QuestionAnatomy and Physiology
# SYNCHRONOUS MULTITREADING
This project consists of writing a **Synchronous Multithreaded Program** that implements *Lohn Algorithm* for Credit card number validation.
## Specifiers
- Create multiple threads, each of which run in parallel creating **Thread-level parallelism**.
- This involves examining the algorithm steps to find areas that can be divided into separate, **concurrent** tasks. Tasks (threads) are independent of one another and thus can run in parallel on multiple computing cores.
- The data accessed by the threads must be examined for dependencies between two or more threads. When one thread depends on data from another, ensure that the execution of the tasks is **synchronized** to accommodate the data dependency.
- In **Synchronous Threading**, parent thread creates multiple children (or worker threads) and then must wait for all of its children to terminate before it resumes. The threads created by the parent perform work concurrently, but the parent cannot continue until this work has been completed. Once each thread has finished its work, it terminates and joins (example: pthread_jent), or Java's (bed.joint) with its parent. Only after all of the children have joined can the parent resume execution.
- Synchronous threading involves significant data sharing among threads. The parent thread combines the results calculated by its various children and outputs the final results.
## Lohn Algorithm
The *Lohn Algorithm* also known as the *Modular 10 check* is a formula that is used to determine whether the identification number provided by a user is accurate. The formula is widely used in validating credit card numbers. The algorithm is used to validate a variety of identification numbers, such as National Provider ID, Canadian SIN, Israeli ID, South African ID, Greek SSN, and International Mobile Equipment ID.
## Lohn Algorithm for Credit card number validation
### Program Steps:
Credit Card numbers follow certain patterns. Verify the following requirements:
- I. A credit card number must have between 13 and 19 digits.
- II. Check if it starts with the major industry identifier of the Issuer identification number:
- 3 for American Express cards
- 6 for Discover cards
- 7 for Master cards
- 8 for Visa cards
| Issuing network | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| American Express | 34, 37 | 16 | Lohn algorithm | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| Discover Card | 6 | 16 - 19 | Lohn algorithm | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| Mastercard | 51 - 55 | 16 | Lohn algorithm | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| Visa | 4 | 13 - 16 | Lohn algorithm | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Card numbers are generated following this validity check which can be described as follows (for illustration, consider the card number 4388576018402626):
- III. Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single digit number.
1. Now add all single-digit numbers from Step III.
4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 + 37
- IV. Add all digits in the odd places from right to left in the card number.
6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38
- V. Sum the results from Step III and Step IV.
37 + 38 = 75
- VI. If the result from Step V is divisible by 10, the card number is valid; otherwise, it is invalid.
## Test Data:
The number 4388576018402626 is invalid. The number 4388576018410707 is valid.
## Implementation:
1. This program will be passed a series of credit card numbers on the command line. Card numbers cannot be hard-coded in the program. Embedding data directly into the source code demands recompiling.
2. Each worker thread will be assigned a computational task of the algorithm. Parent will create separate worker threads for program steps I, II, III, and IV.
3. Once the worker threads have exited, the parent thread will output the following results:
4. a. Display which of the credit card numbers are valid or and which are invalid.
5. b. If valid, display if the card is issued by American Express, Discover, Mastercard, or Visa.
## Language:
1. You can opt for C, C++, or Java.
2. You may solve this using POSIX Pthreads, Windows API, or Java thread API.
## Execution Efficiency:
To measure the efficiency of multithreading, we will compare the execution time of this program versus a single-threaded program.
1. Copy your multi-threaded program, and modify to create a single-threaded program.
2. Measure the program execution times of each.
For example, in Linux, just write `c++` before what you would usually write to run your program from the terminal command line. In the output, the "user" means CPU time.
## Submission
After completion, your program is to report the following:
1. A summary project report. The report details your approach, task allocations, difficulties you overcome, and sources you have used for your project. The report must be in your own words.
2. Source codes exclusively in txt, pdf, or word format.
3. Screenshots of results.
4. Screenshots of execution times for both programs.
Attachments

6 months agoReport content
Answer
Full Solution Locked
Sign in to view the complete step-by-step solution and unlock all study resources.
Step 1**Step 1:** Understand the problem and requirements
We need to write a synchronous multithreaded program that implements the Luhn Algorithm for credit card number validation. The program should receive credit card numbers as command-line arguments, and each worker thread will be assigned a computational task of the algorithm. The parent thread will create separate worker threads for program steps I, II, III, and IV. **Step 2:** Implement the Luhn Algorithm The Luhn Algorithm checks the validity of a credit card number by following these steps:
Step 2
Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single digit number.
Final Answer
The complete C++ code should look like this: ```c++ #include <iostream> #include <pthread.h> #include <string> #include <vector> void* checkLength(2$); void* checkPrefix(2$); void* luhnStep^1(void* arg); void* luhnStep^2(void* arg); void* luhnStep^3(void* arg); void* luhnStep^4(void* arg); void checkDivisibility(2$); int main(2$) { pthread_t threads[4]; // Create worker threads pthread_create(2$); pthread_create(2$); pthread_create(2$); pthread_create(2$); // Wait for worker threads to finish for (int i = 0; i < 4; ++i) { pthread_join(2$); } return 0; } void* checkLength(2$) { // Implementation } void* checkPrefix(2$) { // Implementation } void* luhnStep^1(void* arg) { // Implementation } void* luhnStep^2(void* arg) { // Implementation } void* luhnStep^3(void* arg) { // Implementation } void* luhnStep^4(void* arg) { // Implementation } void checkDivisibility(2$) { // Implementation } ``` Complete the implementation of each function and test the program with various credit card numbers. Make sure to measure the execution time of both the multi-threaded and single-threaded programs to compare their efficiency.
Need Help with Homework?
Stuck on a difficult problem? We've got you covered:
- Post your question or upload an image
- Get instant step-by-step solutions
- Learn from our AI and community of students