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

Sorting

Thread0

Sorting

Thread1

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

Questions Cloud

Do you think they are valid indicators for the variables : The GSS measures a great many variables using answers to questions as indicators. The variables included on past surveys cover a wide range of behaviors, among them drinking behavior,membership in voluntary associations, and the practice of religi..
Treasury want to slow down the rate of expansion : Let's say the economy is growing too fast and the Treasury want to slow down the rate of expansion. How might it use fiscal policy to slow expansion?
Individuals pay the same marginal tax rate : All individuals pay the same marginal tax rate, regardless of income (a flat tax), and ii) there are no exemptions or deductions available when calculating taxable income. In a short essay (2-3 paragraphs) discuss the impact on equity (both types)..
Measure of economic wellbeing : 1. What are the shortcomings of GDP as a measure of total production in an economy, and as a measure of economic wellbeing? 2. How does the existence of financial intermediaries affect liquidity and risk in the financial market?
Designing a multithreaded application : 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. This project consists of designing a multithreaded application that determines whether the solutio..
Calculate closing stock price : You have found the following stock quote for RJW Enterprises, Inc., in the financial pages of today's newspaper VOL NET 52-WEEK YLD LO STOCK (DIV) PE CLOSE CHG 47.97 92.13 RJW 2.20 2.5 19,657 49 Use the reported dividend.
Equation for the average variable cost function : 1. Given the estimated marginal cost function above, write the equation for the average variable cost function and the total variable cost function.
Exploit the workers from developing countries : The Multi-national corporations from the U.S. and other industrialized countries exploit the workers from developing countries. (Use theory of Heckscher-Ohlin model or comparative advantage to discuss this topic.)
Concepts of a shift in the demand curve versus : Use the concepts of a shift in the demand curve versus a movement along the demand curve to explain why this increase in sales does not represent a violation of the law of demand.

Reviews

Write a Review

Operation Management Questions & Answers

  Book review - the goal

Operations Management is about a book review. Title of the book is "Goal". This book has been written by Dr. Eliyahu Goldartt. The book has been appreciated by many as one of those books which offers an insight into the operations and strategic capac..

  Operational plan in hospitality enterprise

Operational plan pertaining to a hospitality enterprise is given in detail in the solution. The operational plan is an important plan or preparation which gives guidelines regarding the role and responsibilities of each and every operation at all lev..

  Managing operations and information

Recognise the importance of a strategic approach to the development and deployment of organisational information systems. Demonstrate an understanding of the importance of databases and their integration to the organisation's overall information mana..

  A make-or-buy analysis

An analysis of the holding costs, including the appropriate annual holding cost rate.

  Evolution and contributor of operations management

Briefly explain Evolution and contributor of Operations management.

  Functions and responsibilities of an operations manager

A number of drivers of change have transformed the roles, functions and responsibilities of an operations manager over recent years. These drivers have not only been based on technological innovations but also on the need for organisations to develop..

  Compute the optimal order quantity

Compute the Optimal Order quantity of DVD players. Determine the appropriate reorder point.

  Relationship to operations practice in the organisation

Evaluate problems in operations and identify approaches to overcoming them. Critically evaluate operating plans and identify areas for improvement. Justify, implement and evaluate changes to operations in line with modern approaches.

  A make or buy analysis

Develop a report for Figi Fabricating that will address the question of whether the company should continue to purchase the part from the supplier or begin to produce the part itself.

  Prepare a staffing plan

Prepare a staffing plan showing the change of your unit from medical/surgical staffing to oncology staffing.

  Leadership styles in different organizations

Ccompare the effectiveness of different leadership styles in different organizations

  Risk management tools and models

Be able to understand the concept of risk, roles and responsibilities for risk management and risk management tools and models.

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