Find Jobs
Hire Freelancers

Sudoku small project!

$10-30 USD

进行中
已发布将近 6 年前

$10-30 USD

货到付款
A sudoku puzzle uses a 9x9 grid in which each columns and row, as well as each of the nine 3x3 sub-grids must contain all of the digits 1. You are required to write the program in C. This project consists of designing a multithreaded application that determines whether the solution to a Sudoku puzzle is valid or not. A thread to check one row of the gird contains the digits 1 through 9, i.e., nine separate threads to check all rows. With the above strategy there are 27 worker threads (plus a main thread) to check whether a given Sudoku grid is valid or not. Your program should ask the user to enter 81 digits from the console (in row-major order, i.e., first the numbers in the first row are entered, then the numbers in the second row, etc.), and the main thread of your program should create the worker threads, passing each worker thread the locations within the grid that it must check. Note that the specific cells to be checked by column validators, row validators, and sub-grid validators are different from each other. You should design your worker threads according to their duties, ensure correct measures on how to obtain the location information from the main thread. In any case this will require passing several parameters to each thread. The simplest approach is to create a data structure using a struct construct of C. For example, a structure to pass the row and column where a thread must begin its validation would appear as follows: /* structure for passing data to threads */ typedef struct { int row; int column; } parameters; Both Pthreads and Windows programs can 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 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 to run as a separate thread. Each worker thread is assigned the task of determining the validity of a particular region of the Sudoku puzzle. Once a worker thread has performed this check, it must pass its results back to the parent. One way to handle this is to create a global 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 thread 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 main thread can check each entry in the result array to determine if the Sudoku puzzle is valid or not. After printing the result to the console, the program should exit. It is apparent from the above discussion that the main thread should wait for all threads to finish their duties before reaching a final decision. This means that the main thread should wait for all the worker threads to exit, and then makes its final decision. You can implement this with the pthread_join function of the Pthreads library (Linux, MAC OS) or via the WaitForMultipleObjects (Windows) function from the Win32 API, as we have seen during our lectures. Alternatively, you can achieve this step via another global integer variable, say threads_completed, initially set to zero, and incremented by every thread when that thread finishes its job, and before it exits. When the value of this variable reaches 27, it means that every thread finished its job, and the main thread can finalize its decision, output the result, and exit. Note that you will need to ensure proper synchronization mechanisms between the threads so that this approach works correctly. You will be using either Pthreads mutex or Windows Mutex objects depending on your development environment.
项目 ID: 16933090

关于此项目

2提案
远程项目
活跃6 年前

想赚点钱吗?

在Freelancer上竞价的好处

设定您的预算和时间范围
为您的工作获得报酬
简要概述您的提案
免费注册和竞标工作
2威客以平均价$45 USD来参与此工作竞价
用户头像
Hello. How are you . I have read I have strong knowledge in Data structures, Algorithms Design, Computer Architecture. And I'm expert in Java, C/C++ etc. I'm interested in this project. Please send me a message so that we can discuss more. Then I'll be happy. I wait for your good reply. Thanks.
$70 USD 在3天之内
4.8 (201条评论)
6.5
6.5
用户头像
sir this is very task for me.i hope you really like my work ,i will do this in less amount and in give time as well.
$20 USD 在1天之内
5.0 (7条评论)
2.8
2.8

关于客户

TURKEY的国旗
istanbul, Turkey
5.0
4
付款方式已验证
会员自3月 19, 2018起

客户认证

谢谢!我们已通过电子邮件向您发送了索取免费积分的链接。
发送电子邮件时出现问题。请再试一次。
已注册用户 发布工作总数
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
加载预览
授予地理位置权限。
您的登录会话已过期而且您已经登出,请再次登录。