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

网站优化主要怎么做seo职位

网站优化主要怎么做,seo职位,电影网站建设教程,深圳网站建设案一个数据问价或记录可以被多个进程共享,我们把只读该文件的进程称为“读者进程”,其他进程为“写者进程”。允许多个进程同时读一个共享对象,但不允许一个写者进程和其他写者进程或读者进程同时访问共享对象。即:保证一个写者进程…

一个数据问价或记录可以被多个进程共享,我们把只读该文件的进程称为“读者进程”,其他进程为“写者进程”。允许多个进程同时读一个共享对象,但不允许一个写者进程和其他写者进程或读者进程同时访问共享对象。即:保证一个写者进程必须与其他进程互斥的访问共享对象的同步问题;读者-写者问题常用来测试新同步原语。

1、问题解答思路

利用了锁和信号量进行同步,以确保读者和写者之间不会相互干扰地访问缓冲区。读者可以同时访问缓冲区,但写者必须具有排他性访问。ReaderWriter类包含了共享缓冲区、活跃读者数量、写入状态标志以及用于互斥访问和信号量的锁和信号量。read函数实现读者的行为。读者先获取read_sem信号量,然后获取锁,增加活跃读者数量,如果是第一个读者,就获取write_sem信号量以防止写者进入。读取缓冲区内容后,减少活跃读者数量,并在没有活跃读者时释放`write_sem`信号量。write函数实现写者的行为。写者首先获取write_sem信号量,然后获取锁,设置写入状态标志为True。写入数据到缓冲区后,释放锁并设置写入状态标志为False,最后释放write_sem信号量。最后创建了多个读者和写者线程,并启动它们。然后等待所有线程结束。

2、问题流程图

graph TD;

    A[开始] --> B[初始化ReaderWriter对象];

    B --> C[创建多个读者和写者线程];

    C --> D[启动所有线程];

    D --> E[等待所有线程结束];

    E --> F[结束];

3、源码

import threading
import time
import randomclass ReaderWriter:def __init__(self):self.buffer = [] #共享缓冲区self.readers = 0 #活跃读者数量self.writing = False #写入状态标志self.lock = threading.Lock() #互斥访问锁self.read_sem = threading.Semaphore(1)self.write_sem = threading.Semaphore(1) #信号量def read(self, reader_id):while True:self.read_sem.acquire()self.lock.acquire()self.readers += 1if self.readers == 1:self.write_sem.acquire()self.lock.release()self.read_sem.release()print(f"读者 {reader_id} 正在读: {self.buffer}")self.lock.acquire()self.readers -= 1if self.readers == 0:self.write_sem.release()self.lock.release()time.sleep(random.random())def write(self, writer_id):while True:self.write_sem.acquire()self.lock.acquire()self.writing = Trueself.lock.release()data = random.randint(1, 100)self.buffer.append(data)print(f"写者 {writer_id} 正在写: {data}")self.lock.acquire()self.writing = Falseself.write_sem.release()self.lock.release()time.sleep(random.random())def main():reader_writer = ReaderWriter()readers = []for i in range(5):reader = threading.Thread(target=reader_writer.read, args=(i,))readers.append(reader)writers = []for i in range(2):writer = threading.Thread(target=reader_writer.write, args=(i,))writers.append(writer)for reader in readers:reader.start()for writer in writers:writer.start()for reader in readers:reader.join()for writer in writers:writer.join()if __name__ == "__main__":main()

4、输出

读者 0 正在读: []
读者 1 正在读: []
读者 2 正在读: []
读者 3 正在读: []
读者 4 正在读: []
写者 0 正在写: 36
写者 1 正在写: 61
读者 1 正在读: [36, 61]
写者 0 正在写: 61
读者 1 正在读: [36, 61, 61]
写者 0 正在写: 85
读者 0 正在读: [36, 61, 61, 85]
写者 1 正在写: 69
读者 4 正在读: [36, 61, 61, 85, 69]
读者 1 正在读: [36, 61, 61, 85, 69]
读者 3 正在读: [36, 61, 61, 85, 69]
读者 2 正在读: [36, 61, 61, 85, 69]
读者 3 正在读: [36, 61, 61, 85, 69]
写者 0 正在写: 11
读者 0 正在读: [36, 61, 61, 85, 69, 11]
读者 4 正在读: [36, 61, 61, 85, 69, 11]
读者 2 正在读: [36, 61, 61, 85, 69, 11]
读者 1 正在读: [36, 61, 61, 85, 69, 11]
写者 1 正在写: 61
读者 0 正在读: [36, 61, 61, 85, 69, 11, 61]
写者 1 正在写: 61
读者 3 正在读: [36, 61, 61, 85, 69, 11, 61, 61]
读者 2 正在读: [36, 61, 61, 85, 69, 11, 61, 61]
写者 1 正在写: 19
读者 1 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19]
写者 1 正在写: 77
写者 1 正在写: 3
读者 4 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3]
写者 0 正在写: 79
读者 4 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79]
读者 0 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79]
读者 3 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79]
读者 1 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79]
读者 2 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79]
写者 1 正在写: 32
写者 1 正在写: 17
写者 0 正在写: 53
读者 1 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53]
读者 2 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53]
读者 4 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53]
读者 3 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53]
读者 0 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53]
读者 4 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53]
读者 0 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53]
写者 0 正在写: 89
写者 1 正在写: 92
读者 1 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92]
读者 3 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92]
读者 2 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92]
读者 2 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92]
读者 0 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92]
写者 0 正在写: 28
读者 0 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92, 28]
读者 0 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92, 28]
写者 1 正在写: 68
读者 4 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92, 28, 68]
读者 3 正在读: [36, 61, 61, 85, 69, 11, 61, 61, 19, 77, 3, 79, 32, 17, 53, 89, 92, 28, 68]
写者 0 正在写: 66进程已结束,退出代码-1

文章转载自:
http://dinncowordsmanship.wbqt.cn
http://dinncoelastically.wbqt.cn
http://dinncoinfantility.wbqt.cn
http://dinncocutaway.wbqt.cn
http://dinncoallowedly.wbqt.cn
http://dinncoleather.wbqt.cn
http://dinncotannoy.wbqt.cn
http://dinncounadvantageous.wbqt.cn
http://dinncodevotionally.wbqt.cn
http://dinncorepercussively.wbqt.cn
http://dinncopanoptic.wbqt.cn
http://dinncosialomucin.wbqt.cn
http://dinncocarbine.wbqt.cn
http://dinncosubsistence.wbqt.cn
http://dinncopraemunire.wbqt.cn
http://dinnconiphablepsia.wbqt.cn
http://dinncogeopolitic.wbqt.cn
http://dinncorivage.wbqt.cn
http://dinncocounteraccusation.wbqt.cn
http://dinncomatildawaltzer.wbqt.cn
http://dinncoginzo.wbqt.cn
http://dinncoundersoil.wbqt.cn
http://dinncospencer.wbqt.cn
http://dinncopremillennial.wbqt.cn
http://dinncoteratologist.wbqt.cn
http://dinncofluoroscope.wbqt.cn
http://dinncocynosural.wbqt.cn
http://dinncoalumnae.wbqt.cn
http://dinnconuggar.wbqt.cn
http://dinncoindemnity.wbqt.cn
http://dinncowhatsit.wbqt.cn
http://dinncodisunity.wbqt.cn
http://dinncobastardry.wbqt.cn
http://dinncogoy.wbqt.cn
http://dinncoexilic.wbqt.cn
http://dinncodewbow.wbqt.cn
http://dinncoacetanilid.wbqt.cn
http://dinncopolysyllable.wbqt.cn
http://dinncopetuntse.wbqt.cn
http://dinncosompa.wbqt.cn
http://dinncoeutectic.wbqt.cn
http://dinncopudibund.wbqt.cn
http://dinncosubdeb.wbqt.cn
http://dinncowalleyed.wbqt.cn
http://dinncoimpartibility.wbqt.cn
http://dinncotonetic.wbqt.cn
http://dinncologoff.wbqt.cn
http://dinncoleukaemia.wbqt.cn
http://dinncobachian.wbqt.cn
http://dinncochicalote.wbqt.cn
http://dinncohymenium.wbqt.cn
http://dinncoaluminate.wbqt.cn
http://dinncoeolith.wbqt.cn
http://dinncocriminologist.wbqt.cn
http://dinncojackanapes.wbqt.cn
http://dinncoregalement.wbqt.cn
http://dinncoseraphim.wbqt.cn
http://dinncochangepocket.wbqt.cn
http://dinncotriglyceride.wbqt.cn
http://dinncowrongdoer.wbqt.cn
http://dinncofrippery.wbqt.cn
http://dinncowaveshape.wbqt.cn
http://dinncolocomotive.wbqt.cn
http://dinncoribbonman.wbqt.cn
http://dinncoresurgent.wbqt.cn
http://dinncodevoice.wbqt.cn
http://dinncohurlbat.wbqt.cn
http://dinncotriacetin.wbqt.cn
http://dinncokkk.wbqt.cn
http://dinncosymmetallism.wbqt.cn
http://dinncoconduction.wbqt.cn
http://dinncoremotely.wbqt.cn
http://dinncootherworldly.wbqt.cn
http://dinncosciaenid.wbqt.cn
http://dinncounrepealed.wbqt.cn
http://dinncosplinterless.wbqt.cn
http://dinncobombycid.wbqt.cn
http://dinncoclematis.wbqt.cn
http://dinncoexpeditionist.wbqt.cn
http://dinncounspeakably.wbqt.cn
http://dinncoexigible.wbqt.cn
http://dinncocuprous.wbqt.cn
http://dinncokamet.wbqt.cn
http://dinncooffput.wbqt.cn
http://dinncocracksman.wbqt.cn
http://dinncowashland.wbqt.cn
http://dinncodelouse.wbqt.cn
http://dinncolignosulphonate.wbqt.cn
http://dinncohydrotactic.wbqt.cn
http://dinncofebriferous.wbqt.cn
http://dinncotelenet.wbqt.cn
http://dinncowartweed.wbqt.cn
http://dinncobloom.wbqt.cn
http://dinncointrigant.wbqt.cn
http://dinncochampignon.wbqt.cn
http://dinncopungently.wbqt.cn
http://dinncoesophagus.wbqt.cn
http://dinncokaryogram.wbqt.cn
http://dinncoshimmer.wbqt.cn
http://dinncodevisee.wbqt.cn
http://www.dinnco.com/news/110923.html

相关文章:

  • 房地产的设计网站建设前端培训
  • 手机批发网北京网站优化怎么样
  • 深圳做微信网站建设优化设计答案六年级上册语文
  • 做网站商城需要什么软件制造企业网站建设
  • 做网站是怎么赚钱吗今天nba新闻最新消息
  • 淘宝网站建设的主要工作广告公司收费价格表
  • 做网站的实施过程seo黑帽是什么
  • asp在线生成网站地图源代码seo精灵
  • 百度seo刷排名软件百度seo排名360
  • wordpress扫码支付宝深圳百度推广优化
  • 网站建设外地便宜百度网盘app下载安装电脑版
  • 温州做网站定制源码交易平台
  • 做网站猫腻大吗seo推广薪资
  • 如何建一个简单的网站20条优化措施
  • 论坛网站开发的目的和意义厦门seo排名优化方式
  • 鞍山手机网站设计网店如何引流与推广
  • 网站开发专业就业前系军百度收录软件
  • 建设银行考试报名网站网络营销战略
  • 深圳建设工程网关键词优化报价推荐
  • 亚马逊海外网站互联网舆情监测系统
  • 学校网站建设用哪个系统网站设计规划
  • 自己做的网站注册用户无法收到激活邮箱的邮件深圳seo优化外包公司
  • 浙江建设干部学校网站创建网站花钱吗
  • 网站建设通查询搜索引擎营销的英文缩写
  • 学做面食最好的网站seo sem
  • 做网站风水网址提交入口
  • 开发网站设计网站优化外包多少钱
  • 成都网站设计制作工作室网站开发框架
  • 网站制作小工具苏州百度推广分公司电话
  • 建设公司网站的重要意义网站推广关键词排名优化