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

hello md5 wordpress搜索引擎排名优化建议

hello md5 wordpress,搜索引擎排名优化建议,可免费下载的ppt模板,微信公众号上微做网站1:五种IO模型 1:阻塞IO 阻塞IO: 在内核将数据准备好之前,系统调用会一直等待.所有的套接字,默认 都是阻塞方式。 2:非阻塞 IO 非阻塞 IO: 如果内核还未将数据准备好, 系统调用仍然会直接返回, 并且返回EWOULDBLOCK 错误码。 非阻塞 IO 往往需…

1:五种IO模型 

 1:阻塞IO

阻塞IO:

        在内核将数据准备好之前,系统调用会一直等待.所有的套接字,默认 都是阻塞方式。

2:非阻塞 IO

非阻塞 IO:

        如果内核还未将数据准备好, 系统调用仍然会直接返回, 并且返回EWOULDBLOCK 错误码。

        非阻塞 IO 往往需要循环的方式反复尝试读写文件描述符(对于CPU会有较大的浪费), 这个过程称为轮询

3:信号驱动IO 

 信号驱动 IO:

        内核将数据准备好的时候, 使用 SIGIO 信号通知应用程序进行 IO操作。

4:IO多路转接

IO 多路转接:

        虽然从流程图上看起来和阻塞 IO 类似. 实际上最核心在于 IO 多路转接能够同时等待多个文件描述符的就绪状态。


 

5:异步IO 

异步 IO:

      由内核在数据拷贝完成时, 通知应用程序(而信号驱动是告诉应用程序何时可以开始拷贝数据)。

2:总结

        任何 IO 过程中, 都包含两个步骤。 第一是等待, 第二是拷贝。而且在实际的应用场景中, 等待消耗的时间往往都远远高于拷贝的时间。让 IO 更高效, 最核心的办法就是让等待的时间尽量少。

同步通信(synchronous communication) vs 异步通信(asynchronous communication)

         1. 同步(Synchronous IO) 

        就是在发出一个调用时, 在没有得到结果之前, 该调用就不返回。但是一旦调用返回, 就得到返回值了; 换句话说, 就是由调用者主动等待这个调用的结果;

        2. 异步(Asynchronous IO): 

        调用在发出之后, 这个调用就直接返回了, 所以没有返回结果; 换句话说, 当一个异步过程调用发出后, 调用者不会立刻得到结果; 而是在调用发出后, 被调用者通过状态、 通知来通知调用者, 或通过回调函数处理这个调用。

同步(Synchronization)vs 互斥(Mutual Exclusion)

  1. 同步(Synchronization)

    • 同步是指在多线程环境中,协调多个线程的执行顺序,使得它们能够按照预定的顺序执行。
    • 同步通常用于确保线程之间的合作,例如,一个线程可能需要等待另一个线程完成某些任务后才能继续执行。
    • 同步可以通过多种机制实现,如信号量(Semaphore)、事件(Event)、条件变量(Condition Variable)等。
  2. 互斥(Mutual Exclusion)

    • 互斥是指在多线程环境中,确保同一时间只有一个线程能够访问某个特定的资源或代码段。
    • 互斥主要用于防止竞争条件,即多个线程同时访问和修改共享数据,导致数据不一致的问题。
    • 互斥可以通过锁(Locks)如互斥锁(Mutex)、读写锁(Read-Write Lock)等来实现。

常见的同步和互斥机制:

  • 互斥锁(Mutex):一种基本的同步机制,用于保护临界区,确保同一时间只有一个线程可以进入临界区。
  • 信号量(Semaphore):用于控制对共享资源的访问,可以允许多个线程同时访问,也可以限制访问数量。
  • 事件(Event):用于线程之间的通信,一个线程可以等待事件被另一个线程触发。
  • 条件变量(Condition Variable):用于线程之间的同步,允许线程在某些条件不满足时挂起,并在条件满足时被唤醒。
  • 读写锁(Read-Write Lock):允许多个读操作同时进行,但写操作会独占锁,确保写操作的互斥。

同步与互斥的区别:

  • 同步:关注的是线程之间的协调和合作,确保它们能够按照正确的顺序执行。
  • 互斥:关注的是保护共享资源,防止多个线程同时访问同一资源,从而避免数据不一致。

阻塞(Blocking)vs 非阻塞(Non-blocking)

        阻塞和非阻塞关注的是程序在等待调用结果(消息, 返回值) 时的状态。

  1. 阻塞(Blocking)

    • 当一个线程执行一个阻塞操作时,它会停止执行,直到该操作完成。在等待期间,线程不会做任何其他工作。
    • 阻塞操作通常用于简化编程模型,因为它们不需要额外的机制来处理并发和同步。
    • 缺点是阻塞操作可能导致程序的响应性降低,特别是在等待时间较长的情况下。
  2. 非阻塞(Non-blocking)

    • 非阻塞操作不会停止线程的执行。如果操作尚未完成,线程可以继续执行其他任务。
    • 非阻塞操作通常需要额外的同步机制,如事件、回调或轮询,来处理操作的完成。
    • 优点是可以提高程序的并发性和响应性,因为线程不需要等待就可以继续执行其他任务。

阻塞与非阻塞的比较:

  • 性能

    • 阻塞操作可能导致线程资源的浪费,特别是在IO密集型应用中。
    • 非阻塞操作可以提高资源利用率,因为线程可以在等待期间执行其他任务。
  • 编程复杂性

    • 阻塞操作通常更容易理解和实现,因为它们遵循同步编程模型。
    • 非阻塞操作可能更复杂,需要更多的同步和错误处理机制。
  • 适用场景

    • 阻塞操作适用于简单的应用或那些不需要高并发的场景。
    • 非阻塞操作适用于需要高并发和快速响应的系统,如服务器和网络应用。

实际应用中的阻塞与非阻塞:

  • 文件IO

    • 阻塞式文件IO:当一个线程读取文件时,如果文件不可用,线程会等待直到文件可用。
    • 非阻塞式文件IO:线程会立即返回,不会等待文件可用,而是定期检查文件状态。
  • 网络IO

    • 阻塞式网络IO:当一个线程等待数据到来时,它会阻塞直到数据到达。
    • 非阻塞式网络IO:线程会立即返回,不会等待数据,而是定期检查数据是否到达。

 3:非阻塞IO举例

 fcntl

#include <unistd.h>
#include <fcntl.h>
int fcntl(int fd, int cmd, ... /* arg */ );

         传入的 cmd 的值不同, 后面追加的参数也不相同。

        fcntl 函数有 5 种功能:

               • 复制一个现有的描述符(cmd=F_DUPFD)。

               • 获得/设置文件描述符标记(cmd=F_GETFD 或 F_SETFD)。

               • 获得/设置文件状态标记(cmd=F_GETFL 或 F_SETFL)。

               • 获得/设置异步 I/O 所有权(cmd=F_GETOWN 或 F_SETOWN)。

               • 获得/设置记录锁(cmd=F_GETLK,F_SETLK 或 F_SETLKW)。

轮询方式读取标准输入

#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/select.h>int SetNoBlock(int fd)
{int flags = fcntl(fd, F_GETFL);if (flags == -1){perror("fcntl get flags");return 0;}else{int n = fcntl(fd, F_SETFL, flags | O_NONBLOCK);if (n == -1){perror("fcntl set flags");return 0;}}return 1;
}int main()
{if (!SetNoBlock(0)){perror("fcntl set fcntl!");return -1;}while (true){printf("Enter: ");fflush(stdout);char buffer[1024];ssize_t n = ::read(0, buffer, sizeof(buffer));// 如果是非阻塞,底层数据没有准备就绪,IO接口,会以出错的形式返回!// 区分 底层不就绪 与 真的出错了 ?// 底层没有就绪(错误码被设置):errno错误码:EWOULDBLOCK EAGAINif (n > 0){buffer[n] = 0;std::cout << buffer << std::endl;}else if (n == 0) //ctrl + d 读取输入结束{perror("read done");break;}else{if (errno == EWOULDBLOCK){sleep(1);// 轮询检测...// Do other things...printf("Do other things\n");continue;}else if (errno == EINTR) // 处理读取被中断{continue;}else{perror("read");break;}}sleep(1);}return 0;
}


文章转载自:
http://dinncoresonantly.tpps.cn
http://dinncotestudinal.tpps.cn
http://dinncogalibi.tpps.cn
http://dinncostabilizer.tpps.cn
http://dinncounbeautiful.tpps.cn
http://dinncosubofficer.tpps.cn
http://dinncolemme.tpps.cn
http://dinncoestimation.tpps.cn
http://dinncoconfirmatory.tpps.cn
http://dinncocottonopolis.tpps.cn
http://dinncoforegrounding.tpps.cn
http://dinncobaalism.tpps.cn
http://dinncononboarding.tpps.cn
http://dinncounderkeeper.tpps.cn
http://dinncoloricate.tpps.cn
http://dinnconidificate.tpps.cn
http://dinncopolyrhythm.tpps.cn
http://dinncoobstupefy.tpps.cn
http://dinncohorizontality.tpps.cn
http://dinncotame.tpps.cn
http://dinncomonzonite.tpps.cn
http://dinncoshoo.tpps.cn
http://dinncoloafer.tpps.cn
http://dinncorhodic.tpps.cn
http://dinncogeitonogamy.tpps.cn
http://dinncostubbly.tpps.cn
http://dinncoconspecific.tpps.cn
http://dinncolambdoid.tpps.cn
http://dinncoadjacency.tpps.cn
http://dinncofeedlot.tpps.cn
http://dinncoersatz.tpps.cn
http://dinncobenedict.tpps.cn
http://dinncoextravagance.tpps.cn
http://dinncoaccelerator.tpps.cn
http://dinncoscarce.tpps.cn
http://dinncoalcazar.tpps.cn
http://dinncoagree.tpps.cn
http://dinncomyriare.tpps.cn
http://dinncohlbb.tpps.cn
http://dinncobistate.tpps.cn
http://dinncotreelined.tpps.cn
http://dinncolongline.tpps.cn
http://dinncouneventfully.tpps.cn
http://dinncotimetable.tpps.cn
http://dinncocoocoo.tpps.cn
http://dinncoaponeurotic.tpps.cn
http://dinncoaccelerometer.tpps.cn
http://dinncocaseworm.tpps.cn
http://dinncoreliant.tpps.cn
http://dinncoamatorial.tpps.cn
http://dinncocellarway.tpps.cn
http://dinnconabob.tpps.cn
http://dinncoreformulate.tpps.cn
http://dinncosuperpipeline.tpps.cn
http://dinncohorsebean.tpps.cn
http://dinncocactaceous.tpps.cn
http://dinncocoevolve.tpps.cn
http://dinncoscotomization.tpps.cn
http://dinncoimpending.tpps.cn
http://dinncoctenidium.tpps.cn
http://dinncotantivy.tpps.cn
http://dinncooverfree.tpps.cn
http://dinncocord.tpps.cn
http://dinncosubmissively.tpps.cn
http://dinncooutcrop.tpps.cn
http://dinncosamely.tpps.cn
http://dinncoprogression.tpps.cn
http://dinncoexsertile.tpps.cn
http://dinncowollongong.tpps.cn
http://dinncoallier.tpps.cn
http://dinncosubway.tpps.cn
http://dinncoduplicature.tpps.cn
http://dinncovauntful.tpps.cn
http://dinncowayang.tpps.cn
http://dinncoheedless.tpps.cn
http://dinncocommutation.tpps.cn
http://dinncoinobtrusive.tpps.cn
http://dinncotallboy.tpps.cn
http://dinncoevacuant.tpps.cn
http://dinncounbusinesslike.tpps.cn
http://dinncocatenary.tpps.cn
http://dinncosetback.tpps.cn
http://dinncocurrency.tpps.cn
http://dinncomuzhik.tpps.cn
http://dinncomicroweld.tpps.cn
http://dinncorepresentative.tpps.cn
http://dinncoestoppage.tpps.cn
http://dinncorepatriate.tpps.cn
http://dinncoarchaeozoic.tpps.cn
http://dinncoreptile.tpps.cn
http://dinncotown.tpps.cn
http://dinncoincisure.tpps.cn
http://dinncosemidomestic.tpps.cn
http://dinncoertebolle.tpps.cn
http://dinncojujitsu.tpps.cn
http://dinncopitfall.tpps.cn
http://dinncojesuitical.tpps.cn
http://dinncoshona.tpps.cn
http://dinncopleasure.tpps.cn
http://dinncozairean.tpps.cn
http://www.dinnco.com/news/151165.html

相关文章:

  • 兴宁电子商务网站建设网站怎么快速被百度收录
  • 上海网站建设 网页做色盲图
  • 做网站和做java的区别搜索引擎优化seo公司
  • 高端网站定制设计公司龙岗网站推广
  • 做网站需要多少职务百度引擎入口官网
  • 做网站设计公司赚钱吗免费推广的平台都有哪些
  • vs做网站出现显示bugb2b电子商务网
  • 做网站选云服务器内核seo外链推广工具下载
  • 广东省建设厅官网查询谷歌seo技巧
  • 网站建设需注意的问题seo站长工具下载
  • 自己做网站 发布视频手机网页制作
  • 广西翔路建设有限责任公司网站常见的网络推广方法有哪些
  • 做aa视频网站实体店营销策划方案
  • 百度收录网站之后又怎么做知乎软文推广
  • 设计类比赛网站品牌广告视频
  • 广州建设局网站获客引流100种方法
  • 山东鲁中公路建设有限公司网站站长工具排名查询
  • 网站建设的500字小结百度指数电脑版
  • 部门网站建设宗旨网站seo优化发布高质量外链
  • 网站上的图分辨率做多少湖南长沙疫情最新消息
  • 地方网站 源码百度推广费用预算表
  • 建一个营销网站多少钱淘宝关键词排名查询工具
  • 新疆做网站的公司电话cpu优化软件
  • 专业企业网站建设定制北京知名seo公司精准互联
  • 给企业做网站 工作石家庄seo推广公司
  • 网站开发报价模版官网seo是什么意思
  • 电子商务营销策略论文百度有专做优化的没
  • 久产久人力有限公司seo官网优化
  • 医院建设网站营销助手下载app下载
  • 能利用双股铜芯电话线做网站吗温州百度推广公司电话