Skip to content

Latest commit

 

History

History
29 lines (17 loc) · 774 Bytes

lab3.md

File metadata and controls

29 lines (17 loc) · 774 Bytes

问题描述

trap_1.png

编写一个 Pthreads 程序使用梯形积分求出函数 𝑓(𝑥)=𝑥^2+𝑥 在区间[𝑎,𝑏]的定积分。使用一个共享变量来表示所有计算线程的总和。在程序中分别使用忙等待,互斥量和信号量三种方式来保证临界区的互斥。

运行方式:./pth_trap <<number of threads>> <<number of method>>

当 method 值为 1 时使用忙等待,method 值为 2 时使用互斥量,method 值为 3 时使用信号量。

输入形式

一行三个数字,分别表示 a, b, n 的值

输出形式

一行一个数字,表示函数 𝑓(𝑥)=𝑥^2+𝑥 在区间[𝑎,𝑏]的定积分

输入样例

0 100 400

输出样例

338334.375000