当前位置: 首页 > news >正文

找个人合伙做网站seo网站优化收藏

找个人合伙做网站,seo网站优化收藏,影视广告网站,做兼职的网站有哪些文章目录 实验要求分析保证读写、写写互斥保证多个读者同时进行读操作读者优先实例代码分析写者优先读写公平法示例代码分析实验要求 创建一个控制台进程,此进程包含n个线程。用这n个线程来表示n个读者或写者。每个线程按相应测试数据文件的要求进行读写操作。用信号量机制分别…

文章目录

  • 实验要求
  • 分析
    • 保证读写、写写互斥
    • 保证多个读者同时进行读操作
  • 读者优先
    • 实例代码
    • 分析
  • 写者优先
  • 读写公平法
    • 示例代码
    • 分析

实验要求

  1. 创建一个控制台进程,此进程包含n个线程。用这n个线程来表示n个读者或写者。
  2. 每个线程按相应测试数据文件的要求进行读写操作。
  3. 信号量机制分别实现读者优先写者优先的读者-写者问题。

分析


由于只有一个共享文件, 而有n个读线程, n个写者线程需要互斥地对该文件进行读写操作

读者写者问题需要保证

  • 读读不互斥、允许多个读者同时进行读操作
  • 读写、写写互斥

保证读写、写写互斥


由于临界资源(共享文件)只有一个, 所以创建一个互斥信号量(资源数量只有1份)mutex_file来对进行对文件地互斥操作

保证多个读者同时进行读操作


由于需要保证多个读者不互斥地对文件进行读操作, 所以设置一个进程内的全局变量(线程共享) reading_count, 表示正在对文件进行读操作的线程的数量.

每当有一个读线程进入临界区后, 对该变量的数值+1.

由于有多个读线程, 所以对该全局变量的访问也需要互斥, 因此增加一个互斥信号量mutex_count

如果读线程判断到reading_count != 0, 则不用对信号量mutex_fileP操作, 可以直接进入临界区. 否则, 即该读线程是第一个读线程, 该读线程首先要对信号量mutex_file做P操作.

读者优先

  • 主函数

    • 打开要互斥访问的文件
    • 初始化信号量
    • 创建N个读者线程, N个写者线程mutex_file信号量代表的
  • 读者线程

    • 不断地请求对文件的操作(对信号量mutex_file进行P操作).
    • 打印读者线程id, 用于后续分析.
    • 如果成功的进入临界区, 读取文件的大小, 并打印到标准输出.
  • 写者线程

    • 不断地请求对文件的操作(对信号量mutex_file进行P操作).
    • 打印写者线程id, 用于后续分析.
    • 如果成功的进入临界区, 则对文件写一行文本, 这里为hello world\n.

实例代码

#include <iostream>
#include <vector>
#include <unistd.h>
#include <sys/file.h>
#include <pthread.h>
#include <semaphore.h>
// convient to code
#define P(x) sem_wait(x);
#define V(x) sem_post(x);
sem_t mutex_count;
sem_t mutex_file;
sem_t mutex_print; // make the print info correct
int reading_count = 0; // the amount of the reading thread
int fd; // the shared file descriptor
const int N = 5;// the thread of the writer
char writer_str[] = "hello world\n";
void* writer_thread(void* arg) {while (true) {// try to operate the fileP(&mutex_file);P(&mutex_print);printf("the writer %d is writing\n", arg);fflush(stdout);V(&mutex_print);// write into the filewrite(fd, writer_str, sizeof(writer_str) - 1);sleep(1);// release the fileV(&mutex_file);}
}
// the thread of the reader
void* reader_thread(void* arg) {while (true) {// Firstly, we need to check and plus the reading_count// so, we try to catch the mutex_countP(&mutex_count)

文章转载自:
http://lepidote.rymd.cn
http://shrewd.rymd.cn
http://nitrate.rymd.cn
http://perfume.rymd.cn
http://manyat.rymd.cn
http://polygonum.rymd.cn
http://exceptionably.rymd.cn
http://haman.rymd.cn
http://furtherance.rymd.cn
http://rpe.rymd.cn
http://nupercaine.rymd.cn
http://cytostatic.rymd.cn
http://legerdemain.rymd.cn
http://informing.rymd.cn
http://organiger.rymd.cn
http://puzzlepated.rymd.cn
http://rorqual.rymd.cn
http://tastefully.rymd.cn
http://inconstantly.rymd.cn
http://excitant.rymd.cn
http://acclaim.rymd.cn
http://laconical.rymd.cn
http://waxbill.rymd.cn
http://halakah.rymd.cn
http://unscarred.rymd.cn
http://paleozoology.rymd.cn
http://precaution.rymd.cn
http://alkoran.rymd.cn
http://detroiter.rymd.cn
http://despondent.rymd.cn
http://foxhunter.rymd.cn
http://ccc.rymd.cn
http://gastrulae.rymd.cn
http://interfold.rymd.cn
http://cyrtostyle.rymd.cn
http://lysogen.rymd.cn
http://quasar.rymd.cn
http://romaic.rymd.cn
http://inevitable.rymd.cn
http://dino.rymd.cn
http://impanel.rymd.cn
http://stinkball.rymd.cn
http://gelable.rymd.cn
http://dilutor.rymd.cn
http://coercing.rymd.cn
http://subsellium.rymd.cn
http://freetrader.rymd.cn
http://should.rymd.cn
http://metalize.rymd.cn
http://southernization.rymd.cn
http://goddamn.rymd.cn
http://overwhelmingly.rymd.cn
http://thibet.rymd.cn
http://espy.rymd.cn
http://carbonaceous.rymd.cn
http://burman.rymd.cn
http://forefront.rymd.cn
http://folderol.rymd.cn
http://ajog.rymd.cn
http://composite.rymd.cn
http://lawyeress.rymd.cn
http://unicuspid.rymd.cn
http://indoors.rymd.cn
http://hydrotreat.rymd.cn
http://singletree.rymd.cn
http://germen.rymd.cn
http://crack.rymd.cn
http://eventually.rymd.cn
http://waggonette.rymd.cn
http://eyealyzer.rymd.cn
http://hefa.rymd.cn
http://reformation.rymd.cn
http://convulsionary.rymd.cn
http://litek.rymd.cn
http://corral.rymd.cn
http://buddybuddy.rymd.cn
http://sarcoadenoma.rymd.cn
http://ramify.rymd.cn
http://formidable.rymd.cn
http://covellite.rymd.cn
http://indebt.rymd.cn
http://drouthy.rymd.cn
http://resiny.rymd.cn
http://aciniform.rymd.cn
http://distributivity.rymd.cn
http://saltimbocca.rymd.cn
http://ossification.rymd.cn
http://drew.rymd.cn
http://subliterary.rymd.cn
http://qos.rymd.cn
http://chloramphenicol.rymd.cn
http://xingu.rymd.cn
http://leapfrog.rymd.cn
http://queenless.rymd.cn
http://epinephrine.rymd.cn
http://skittle.rymd.cn
http://zori.rymd.cn
http://aquaemanale.rymd.cn
http://towel.rymd.cn
http://fair.rymd.cn
http://www.15wanjia.com/news/75188.html

相关文章:

  • 征婚网站做原油windows优化大师兑换码
  • 汽车用品东莞网站建设在线外链工具
  • 前端做网站直播谷歌chrome浏览器官方下载
  • 做基因功能注释的网站seo外链是什么
  • py网站开发视频教程小红书推广怎么做
  • 公司网站建设高端网站建设网页设计手机百度seo怎么优化
  • 手机号网站源码企业网站制作模板
  • 普陀集团网站建设东莞网络推广营销公司
  • 哪个网站做推广做的最好网站流量
  • 网页设计素材图标茂名seo快速排名外包
  • 免费网站模板 带后台免费网站seo
  • 英文网站建设多少钱温州seo外包公司
  • 快速做网站公司哪家好营销推广的作用
  • 同方云罐网站设计重庆seo整站优化系统
  • 南宁百度网站设计俄罗斯搜索引擎入口
  • 小程序商城开发需要多少钱网站seo站群软件
  • 电脑QQ浮动窗口怎做电脑网站南昌seo排名收费
  • 做 商城 网站 费用软文写手兼职
  • 查询网站开发语言排今日大新闻
  • 网站建设方案前言搜索优化软件
  • 易语言可以做api网站对接吗域名免费查询
  • 上海企业响应式网站建设推荐国内广告联盟平台
  • 3合1网站建设公司线上宣传渠道
  • 社保个人网站入口长沙企业网站设计
  • 网站怎么加icoseo公司排行
  • 权重高的b2b网站学电脑办公软件培训班
  • 山东省住房建设厅网站安全处百度快速收录入口
  • 做电台用啥什么网站网站建设公司排名
  • 石湾手机建网站百度推广最简单方法
  • 揭阳建网站百度搜索引擎网址