mplement a Multithreaded Sudoku Solution Validator using POSIX thread library in C Specifications This assignment consists of designing a multithreaded application that determines whether the solution to a Sudoku puzzle is valid.
Implement a Multithreaded Sudoku Solution Validator using POSIX thread library in C
Specifications
This assignment consists of designing a multithreaded application that determines whether the solution to a Sudoku puzzle is valid.
A Sudoku puzzle uses a 9×9 grid in which each column and row, as well as each of the nine 3×3 subgrids, must contain all of the digits 1 to 9. Following figure presents an example of a valid Sudoku puzzle solution.
There are several different ways of multithreading this application. In this assignment, you need to implement the strategy to create multiple worker threads that check the following criteria:
Nine threads to check that each of the 9 columns contains the digits 1 through 9
Nine threads to check that each of the 9 rows contains the digits 1 through 9
Nine threads to check that each of the 3×3 subgrids contains the digits 1 through 9
This would result in a total of 27 separate worker threads for validating a Sudoku puzzle solution.
The parent thread will create the worker threads, passing each worker thread the location that it must check in the Sudoku grid. The location of a column, row, and subgrid can be represented by the row and column value of the first cell of the column, row, and subgrid respectively. For example, the location of column 5 is [0, 4], the location of row 5 is [4, 0], the location of the last subgrid is [6, 6]. A data structure using a struct can be created to represent the location. For example, a structure to pass the thread number, the row, and the column where a thread must begin validating might be as follows:
/* structure for passing data to threads */ typedef struct {
int thread_no;
int row;
int column; } parameters;
Function pthread_create() from <pthread> library can be used to create each worker thread. The code that will be executed under a worker thread is passed as a function pointer parameter to pthread_create() function. The parameters necessary to the worker function are also passed as a pointer parameter to pthread_create() function. Three different types of worker functions will be required to solve this problem. One worker function will check the validity of a specific column. Another worker function will check the validity of a specific row, and the third worker function will check the validity of a specific subgrid. Each worker thread is assigned the task of determining the validity of a particular region of the Sudoku puzzle. Once a worker has performed this check, it must pass its results back to the parent. One good way to handle this is to create an array of integer values that is visible to each thread. The ith index in this array corresponds to the ith worker thread. If a worker sets its corresponding value to 1, it is indicating that its region of the Sudoku puzzle is valid. A value of 0 would indicate otherwise. When all worker threads have completed, the parent thread checks each entry in the result array to determine if the Sudoku puzzle is valid.
Your program must accept the name of a file as an argument and read a Sudoku puzzle solution from that file. Your program must handle error while reading from file.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images