
Concept explainers
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 nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

- java uses fixed stack dynamic arrays for arrays of primitive types True Falsearrow_forwardJava Programming language Please help me with this. Thanks in advance.arrow_forwardin c++ using 2D Arrays The following diagram represents an island with dry land (represented by “-“) surrounded by water ((represented by “#“). ##-########## #-----------# #-----------# #------------ # -----------# #------X----# #-----------# ############# Two bridges lead off the island. A mouse (represented by “X”) is placed on the indicated square. Write a program to make the mouse take a walk across the island. The mouse is allowed to travel one square at a time, either horizontally or vertically. A random number from 1 to 4 should be used to decide which direction the mouse is to take; for the sake of uniformity assume that 1 = up, 2 = down, 3 = left, and 4 = right. Since the mouse is wearing cement mouse galoshes, the mouse drowns when he hits the water. He escapes when he steps on a bridge. You may generate a random number up to 100 times allowing the mouse to take 100 steps. If the mouse does not find a bridge by the 100th try, he will wither away and die of starvation.…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





