Designing a multithreaded application

Assignment Help Operation Management
Reference no: EM131441622

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 • • • 9. Figure 4.19 presents an example of a valid Sudoku puzzle. This project consists of designing a multithreaded application that determines whether the solution to a Sudoku puzzle is valid.

There are several different ways of multithreading this application. One suggested strategy is to create threads that check the following criteria:

  • A thread to check that each column contains the digits 1 through 9
  • A thread to check that each rowcontains 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 eleven separate threads for validating a Sudoku puzzle. However, you are welcome to create even more threads for this project. For example, rather than creating one thread that checks all nine 198 Chapter 4 Threads columns, you could create nine separate threads and have each of them check one column.

6 2 4 5 3 9 1 8 7

5 1 9 7 2 8 6 3 4

8 3 7 6 1 4 2 9 5

1 4 3 8 6 5 7 2 9

9 5 8 2 4 7 3 6 1

7 6 2 3 9 1 4 5 8

3 7 1 9 5 6 8 4 2

4 9 6 1 8 2 5 7 3

2 8 5 4 7 3 9 1 6

Figure 4.19 Solution to a 9 × 9 Sudoku puzzle.

Passing Parameters to Each Thread

The parent thread will create the worker threads, passing each worker the location that it must check in the Sudoku grid. This step will require passing several parameters to each thread. The easiest approach is to create a data structure using a struct. For example, a structure to pass the row and column where a thread must begin validating would appear as follows:

/* structure for passing data to threads */

typedef struct

{ int row;

int column;

} parameters;

Both Pthreads and Windows programs will create worker threads using a strategy similar to that shown below:

parameters *data = (parameters *) malloc(sizeof(parameters));

data->row = 1;

data->column = 1;

/* Now create the thread passing it data as a parameter */

The data pointer will be passed to either the pthread create() (Pthreads) function or the CreateThread() (Windows) function, which in turn will pass it as a parameter to the function that is to run as a separate thread.

Returning Results to the Parent Thread

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 Bibliographical Notes 199

7, 12, 19, 3, 18

7, 12, 19, 3, 18, 4, 2, 6, 15, 8

Original List

2, 3, 4, 6, 7, 8, 12, 15, 18, 19

Merge Thread

Sorted List





4, 2, 6, 15, 8

Figure 4.20 Multithreaded sorting.

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.

Reference no: EM131441622

What is probability that both service desk clerks are busy

Sharp discount Wholesale club has two service desks, one at each entrance of the store. Customers arrive at each customer service desk at an average of one every six minutes.

Annual inventory cost under the optimal inventory policy

Inventory Management, EOQ In 2014, BabyStuff, a fictional U.S. manufacturer of children's apparel has an average inventory of around $350,000,000, and the cost of goods sold i

Quantify cost variance-is project ahead or behind budget

Amy’s project is to produce 300 widgets and is scheduled to take five weeks. Each unit is planned to cost $90. The project is severely cost constrained. Quantify cost variance

Explain the functions of management

What are the four functions of management? Define them. How do these functions relate to the goals of an organization? What is the relationship of efficiency and effectiveness

Marketing plan for insurance call centre

A marketing plan for insurance call centre - it has to include (1)Executive Summary (2) Product or Service Description (3) Swot Analysis (4) Target Market (5)Competitive Analy

Contrast these two architectures

It seems that more and more applications are becoming web-based (sometimes referred to as “the cloud” or “cloud computing”). This prevents the user from having to download the

Social responsibility performance

Why should a corporation report on its social responsibility performance? Research on the Internet an example of a corporate social responsibility report. Present a brief summ

Why is identity theft difficult to prosecute

Find a story about identity theft and report how the victims were scammed. Explain what steps you personally take and/or would recommend to the local community on how to prote


Write a Review

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd