Java Python Lab02: Multithreaded programming
Due date
Please refer to the lab assignment requirements. Goal
The goal of this project is (1) to obtain a good understanding of multi-threading, (2) to
practice creating threads and coordinate the running of the threads. Part I—Sudoku Solution Validator
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. The following figure 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 row contains the digits 1 through 9
Nine threads to check that each of the 3 × 3 subgrids contains the digits 1
through 9This 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 columns, you could create nine
separate threads and have each of them check one column. 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 orthe 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 program、C/C++ 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 i
th
index in this array corresponds to the i
th 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. Part II—Multithreaded Sorting Application
Write a multithreaded sorting program that works as follows: A list of integers is divided
into two smaller lists of equal size. Two separate threads (which we will term sorting
threads) sort each sublist using a sorting algorithm of your choice. The two sublists are
then merged by a third thread—a merging thread —which merges the two sublists into a
single sorted list.
Fig 2. Multithreaded sorting. Because global data are shared cross all threads, perhaps the easiest way to set up the
data is to create a global array. Each sorting thread will work on one half of this array. A
second global array of the same size as the unsorted integer array will also be established.The merging thread will then merge the two sublists into this second array. Graphically,
this program is structured according to Figure 2. This programming project will require
passing parameters to each of the sorting threads. In particular, it will be necessary to
identify the starting index from which each thread is to begin sorting. Refer to the
instructions in Project 1 for details on passing parameters to a thread. The parent thread will output the sorted array once all sorting threads have exited. Submission
Your submission should include the code, a readme file briefly describing your design, how to compile/use your code and, and a report which consists of (but not limited to) the
following parts:
Summarize the thread control methods provided by Linux(or Windows, if applied), and describe the usage. Your design of the program
Snapshots of experimental results(statistics) with analysis
Problems encountered and your solution
Reference materials
Your suggestions and comments
Environment
Linux (recommended, any kernel after 2.6 is fine) and C/C++
相关推荐
深度解读扫地机器人的导航原理
科技改变生活,不可否认科技的进步的确为我们的生活带来许多便捷,以智能家电为例,智能电饭煲、智能洗碗机、智能扫地机等产品已逐渐成为家庭的一分子,其中以扫地机表现最为抢眼。能做到智能规划清扫,收割了不少家庭主妇及科技爱好者的芳心。但扫地机并非一开始就这么智能,最初的扫地机只能做到随机式清扫,会频繁出现碰撞现象。 近年来,通过业界的不断努力,目前,扫地机器人已告别乱碰乱撞现象,能做到自主路径...
c语言编译成功,[C/CPP系列知识] 那些程序C语言可以编译通过但C++无法编译成功 Write a C program that won’t compile in C++...
下面的程序可以用gcc编译,但g++无法编译。#includeintmain(){foo();//foo() is called before its declaration/definition}intfoo(){printf("Hello");return 0;}编译结果:diego@ubuntu:~/myProg/geeks4geeks/cpp$ gcc test3.cdiego@ubunt...
【ROS学习笔记】13.ROS中的坐标管理系统
文章目录1 机器人中的坐标变换2 TF功能包TF坐标变换如何实现?TF的一个小案例3 小程序:小海龟跟随实验打开小程序查看当前的TF树坐标相对位置关系可视化1(tf_echo)坐标相对位置关系可视化2(rviz) 本节学习ROS中的坐标管理系统。 (部分图摘自:b站【古月居】古月·ROS入门21讲) 1 机器人中的坐标变换 机器人运动学的核心,描述任意两个坐标系之中任意两个向量之间的变换,可以用一个4×4的变换矩阵(Transformation Matrices)来描述它的平移和旋转变化。 变换矩阵中有包括
(踩坑)Visual Studio Code(VS code)配置C/C++环境报错:launch: program ‘xxx‘ does not exist
关于VScode配置C/C++环境的教程很多,但是本人按照教程操作总是不能成功,最终将本人遇到的问题以及解决方案展示如下: 根据教程https://www.cnblogs.com/bpf-1024/p/11597000.html,以此完成: 1、VScode下载 2、安装cpptool工具 3、下载MinGW 4、验证环境变量配置成功 对于第5步,本人按照步骤: (1)新建文件夹code (2)在vscode软件中打开code文件夹 (3)在code文件夹下新建一个test.cpp文件。
基于Codex与Skills的学术研究自动化全流程实战指南
还在为海量文献下载、整理、阅读和综述写作而头疼吗?面对堆积如山的PDF,你是否感到无从下手?从选题、文献检索、到写作、绘图、润色,再到应对AI检测和审稿意见,学术研究的每一步都充满挑战。本文将为你带来一套堪称“王炸组合”的解决方案: Codex + Skills 。这不是简单的工具介绍,而是一套从零开始,覆盖学术研究全流程的保姆级实战教程。我们将手把手教你如何安装、配置,并利用强大的Skills(技能)自动化处理文献下载管理、高效撰写综述、生成专业图表、智能润色降重,直至应对审稿。无论你是科研新手还是希望提
1、机器学习在环境科学中的应用与经典数据分析基础
本文介绍了机器学习在环境科学中的广泛应用,包括卫星遥感、气候预测、空气质量预报等领域,并系统回顾了经典数据分析的基本概念,如期望、方差、协方差和相关性及其显著性检验。同时,文章阐述了贝叶斯定理、判别函数与分类、聚类分析等方法的原理与应用,强调了经典统计方法与机器学习技术的互补关系。最后展望了未来环境科学中数据分析的发展方向,强调多学科融合与方法创新的重要性。
program c/c++
machine.git3 Overviewsetpgid.1command?Options:tsh> quitdiffer.Options。
【Android OpenGL ES】阅读hello-gl2代码(四)C/C++代码
JNI函数实现 extern "C" { JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj, jint width, jint height); JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2...
新手友好!C#上位机调用YOLO实现设备异常检测(详细步骤,附踩坑指南)
C#上位机调用YOLO实现设备异常检测,核心是把“工控交互”和“AI检测”的优势结合起来,新手不用追求一步到位,先跑通基础流程,再逐步优化性能和功能。我当初也是从踩坑中过来的,只要把核心链路和细节摸透,其实门槛并没有想象中高。如果你们在实操中遇到了具体问题(比如相机取流卡顿、模型推理报错),可以在评论区留言,后续我也可以针对性拆解具体模块的完整代码。
4D毫米波雷达:高度信息与微多普勒效应
4D毫米波雷达:高度信息与微多普勒效应 ,人工智能,计算机视觉,大模型,AI,本文深入解析4D毫米波雷达的高度信息获取与微多普勒效应。4D毫米波雷达通过MIMO技术、垂直天线布局及相位差计算等获取高度信息,相较传统雷达更精准。微多普勒效应由目标微运动引发,可用于目标识别、分类和运动监测。文中结合自动驾驶、安防监控案例,分析技术挑战与未来趋势,如信号干扰、数据处理复杂,未来将向高精度、与其他传感器融合发展,展现出在多领域的巨大应用潜力。
C/C++ Program Technique Note
C\C++ Technical Summary1.Explicit Key Word2.Volatile Key Word3.How to Convert C Pointer to Ref Implement Auto Release 1.Explicit Key Word 2.Volatile Key Word 3.How to Convert C Pointer to Ref Implem...
【25届数字IC秋招总结】面试经验15——比特大陆-算能
25届数字ic面试记录——比特大陆-算能
program JAVA Python C/C++
should return the exact same estimate values as the pdai 写program、JAVA, Python, C/C++ rograms of Part I;
迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)
迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)
ET2012新版免狗免安装绿色软件
ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,
[C/CPP系列知识] 那些程序C语言可以编译通过但C++无法编译成功 Write a C program that won’t compile in C++...
http://www.geeksforgeeks.org/write-c-program-wont-compiler-c/ 1) C++中在函数声明之前调用一个函数会引发错误,但是在C中有可能可以。 参考 http://www.cnblogs.com/diegodu/p/4580292.html 下面的程序可以用gcc编译,但g++无法编译。 #include<stdio.h...
IEM模型,地表粗糙度模拟
利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟
program c/c++ java
EDITED BYCITATIONCOPYRIGHTKEYWORDSLi et al.FIGURE 1Li et al.DatasetFIGURE 2Li et al.FIGURE 3Li et al.FIGURE 405FIGURE 5FIGURE 6。
ssm框架搭建
这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载
VS Code中C/C++环境报错:launch: program ‘路径‘ does not exist
本人由于报错时根本没有构建.vscode文件夹,所以对于第三种方法不太了解不做说明。3.对.vscode文件夹下的launch.json和task.json进行相应修改。完成以上步骤之后如果按照教程测试安装成功后,重启vscode就可以成功调试C代码了。主要参考该教程,这个教程很详细,关于构建C/C++环境相关的流程和问题基本有说明。2.在MYMS2终端安装Mingw-w64(具体流程教程中非常详细的说明了)2.没有安装MinGW或没有将对应路径加入环境变量。1.下载安装MYMS2(直接搜索官网下载就行)
Compile c/c++ program on ubuntu
1.Open up a terminal on Ubuntu Linux and install the build-essential package by typing the following command in the terminal sudo apt-get install build-essential 2.Create a directory and a su
6506



被折叠的 条评论
为什么被折叠?



