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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Race Condition
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning