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

  Why is supply or material acquisition important

Why is supply or material acquisition important? Also, is the position of supply management within a corporation's organizational hierarchy important? Finally, how does availability of materials and services, absolute dollar value of purchases, perce..

  Analyze and rank the sources with regard to reliability

Using the Web and other venues of your choice, identify three to four sources of information for trend data about the subject you chose in Step 2. Analyze and rank the sources with regard to (1) Reliability, (2) Believability, (3) Pertinence to yo..

  Calculate repayment of principal

Jan sold her house on December 31 and took a $50,000 mortgage as part of the payment. The 10-year mortgage has a 11% nominal interest rate, but it calls for semiannual payments beginning next June 30.

  Name four methods of quantitative analysis

Name four methods of quantitative analysis that are useful in informing the facility location decision. How can each of the methods assist you in location decisions. Provide examples for each of the four.

  Draft bill providing the federal communications commission

You work for a U.S. senator, who asks you to draft a bill providing the Federal Communications Commission (FCC) with the authority to seize cellular telephones that are manufactured, sold, or used in violation of federal law.

  Persons behavior affect attitude of the other group members

Describe a situation in which you were part of a formal work group and one of the members of the group did not contribute much work to the project. How did the other group members deal with this person? How did this person’s behavior affect the attit..

  Examples of cultural preferences of leaders

Do you have an example of an organization that you have seen (or researched) having gone the organizational life cycle? What are some examples of "cultural preferences of leaders?"

  Think are the characteristics of effective performance

People play a key role in the success of the organization regardless of the type of business or industry. They create the culture that is embedded in the organization and embraced by the stakeholders. Based upon your work experience what do you think..

  Analyze the differences between product and services

how you would modify the process based on those differences. What are two things that you would do to be sure the service is performing up to customers' expectations?

  Management implement this new strategy

Play Around Toys Inc. operates stores in different regions of the country. The senior management of Play Around Toys Inc. has decided to tailor the merchandise selection for each store based on its sales patterns. How could information systems help m..

  Budget to traditional media advertising

Evaluate Nike’s decision to move away from the use of traditional mass-media advertising and focus more of its marketing budget on digital media. Do you agree with this decision or do you think Nike should be allocating more of its IMC budget to trad..

  Your chosen profession so far

For this unit, you will write a 3-5 page paper (excluding title and reference pages) summarizing what you have learned about your chosen profession so far.

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