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

h5响应式网站建设代理wordpress密文

h5响应式网站建设代理,wordpress密文,河源网站建设1993seo,帮忙做公司网站线程间通信之eventfd man手册中的解释#xff1a; eventfd()创建了一个“eventfd对象”#xff0c; 通过它能够实现用户态程序间(我觉得这里主要指线程而非进程)的等待/通知机制#xff0c;以及内核态向用户态通知的机制#xff08;未考证#xff09;。 此对象包含了一个…线程间通信之eventfd man手册中的解释 eventfd()创建了一个“eventfd对象” 通过它能够实现用户态程序间(我觉得这里主要指线程而非进程)的等待/通知机制以及内核态向用户态通知的机制未考证。 此对象包含了一个被内核所维护的计数uint64_t, 初始值由initval来决定。 int eventfd(unsigned int initval, int flags);创建一个eventfd文件描述符 int eventfd_read(int fd, eventfd_t *value); 向eventfd中写入一个值 int eventfd_write(int fd, eventfd_t value); 从eventfd中读出一个值 例一、子线程多次写入多个值主线程一次读出所有值的和 1 #include sys/eventfd.h2 #include unistd.h3 #include stdlib.h4 #include stdio.h5 #include stdint.h 6 7 int main(int argc, char**argv[])8 {9 int efd, j; 10 uint64_t u; 11 ssize_t s; 12 13 if (argc 2) 14 { 15 printf(number of argc is wrong!\n); 16 return 0; 17 } 18 19 efd eventfd(0,0); 20 if (-1 efd) 21 { 22 printf(failed to create eventfd\n); 23 } 24 25 switch(fork()) 26 { 27 case 0: 28 { 29 for(j1; jargc;j) 30 { 31 printf(child writing %s to efd\n, argv[j]); 32 u strtoull(argv[j], NULL, 0); 33 s write(efd, u, sizeof(uint64_t)); 34 if (s!sizeof(uint64_t)) 35 { 36 printf(write efd failed\n); 37 } 38 } 39 printf(Child completed write loop\n); 40 exit(0); 41 } 42 default: 43 sleep(2); 44 printf(Parents about to read\n); 45 s read(efd, u, sizeof(uint64_t)); 46 if (s ! sizeof(uint64_t)) 47 { 48 printf(read efd failed\n); 49 } 50 printf(Parents first read %llu (0x%llx) from efd\n, u, u); 51 exit(0); 52 case -1: 53 { 54 printf(fork error\n); 55 } 56 } 57 58 return 0; 59 } 60 61 运行结果 62 kanekanelinux:/mnt/hgfs/kanelinuxshare/eventfd$ ./a.out 1 2 3 4 63 child writing 1 to efd 64 child writing 2 to efd 65 child writing 3 to efd 66 child writing 4 to efd 67 Child completed write loop 68 Parents about to read 69 Parents first read 10 (0xa) from efd 70 71 如果有写入操作但是并没有导致初始值变化则主线程会一直挂在read操作上 72 kanekanelinux:/mnt/hgfs/kanelinuxshare/eventfd$ ./a.out 0 0 0 0 73 child writing 0 to efd 74 child writing 0 to efd 75 child writing 0 to efd 76 child writing 0 to efd 77 Child completed write loop 78 Parents about to read 79 ^C 例二、eventfd可以被epoll监控 一旦有状态变化可以触发通知 1 #include sys/eventfd.h2 #include unistd.h3 #include stdlib.h4 #include stdio.h5 #include stdint.h 6 #include sys/epoll.h 7 #include string.h 8 #include pthread.h 9 10 int g_iEvtfd -1;11 12 void *eventfd_child_Task(void *pArg)13 {14 uint64_t uiWrite 1;15 16 while(1)17 {18 sleep(2);19 if (0 ! eventfd_write(g_iEvtfd, uiWrite))20 {21 printf(child write iEvtfd failed\n);22 } 23 }24 25 return;26 }27 28 int main(int argc, char**argv[])29 {30 int iEvtfd, j;31 uint64_t uiWrite 1;32 uint64_t uiRead;33 ssize_t s;34 int iEpfd;35 struct epoll_event stEvent;36 int iRet 0;37 struct epoll_event stEpEvent;38 pthread_t stWthread;39 40 iEpfd epoll_create(1);41 if (-1 iEpfd)42 {43 printf(Create epoll failed.\n);44 return 0;45 }46 47 iEvtfd eventfd(0,0);48 if (-1 iEvtfd)49 {50 printf(failed to create eventfd\n);51 return 0;52 }53 54 g_iEvtfd iEvtfd;55 56 memset(stEvent, 0, sizeof(struct epoll_event));57 stEvent.events (unsigned long) EPOLLIN;58 stEvent.data.fd iEvtfd;59 iRet epoll_ctl(iEpfd, EPOLL_CTL_ADD, g_iEvtfd, stEvent);60 if (0 ! iRet)61 {62 printf(failed to add iEvtfd to epoll\n);63 close(g_iEvtfd);64 close(iEpfd);65 return 0;66 }67 68 iRet pthread_create(stWthread, NULL, eventfd_child_Task, NULL);69 if (0 ! iRet)70 {71 close(g_iEvtfd);72 close(iEpfd);73 return;74 }75 76 for(;;)77 {78 iRet epoll_wait(iEpfd, stEpEvent, 1, -1);79 if (iRet 0)80 {81 s eventfd_read(iEvtfd, uiRead);82 if (s ! 0)83 {84 printf(read iEvtfd failed\n);85 break;86 }87 printf(Read %llu (0x%llx) from iEvtfd\n, uiRead, uiRead);88 }89 }90 91 close(g_iEvtfd);92 close(iEpfd);93 return 0;94 }95 运行结果96 kanekanelinux:/mnt/hgfs/kanelinuxshare/eventfd$ ./a.out97 Read 1 (0x1) from iEvtfd98 Read 1 (0x1) from iEvtfd99 Read 1 (0x1) from iEvtfd 100 Read 1 (0x1) from iEvtfd 101 Read 1 (0x1) from iEvtfd 102 Read 1 (0x1) from iEvtfd 103 Read 1 (0x1) from iEvtfd 104 Read 1 (0x1) from iEvtfd 105 ^C 例三、被epoll监控的eventfd如果在子线程中被多次写入在主线程中是怎么读的 #include sys/eventfd.h #include unistd.h #include stdlib.h #include stdio.h #include stdint.h #include sys/epoll.h #include string.h #include pthread.h int g_iEvtfd -1;void *eventfd_child_Task(void *pArg) {uint64_t uiWrite 1;while(1){sleep(2);eventfd_write(g_iEvtfd, uiWrite);eventfd_write(g_iEvtfd, uiWrite);}return; }int main(int argc, char**argv[]) {int iEvtfd, j;uint64_t uiWrite 1;uint64_t uiRead;ssize_t s;int iEpfd;struct epoll_event stEvent;int iRet 0;struct epoll_event stEpEvent;pthread_t stWthread;iEpfd epoll_create(1);if (-1 iEpfd){printf(Create epoll failed.\n);return 0;}iEvtfd eventfd(0,0);if (-1 iEvtfd){printf(failed to create eventfd\n);return 0;}g_iEvtfd iEvtfd;memset(stEvent, 0, sizeof(struct epoll_event));stEvent.events (unsigned long) EPOLLIN;stEvent.data.fd iEvtfd;iRet epoll_ctl(iEpfd, EPOLL_CTL_ADD, g_iEvtfd, stEvent);if (0 ! iRet){printf(failed to add iEvtfd to epoll\n);close(g_iEvtfd);close(iEpfd);return 0;}iRet pthread_create(stWthread, NULL, eventfd_child_Task, NULL);if (0 ! iRet){close(g_iEvtfd);close(iEpfd);return;}for(;;){iRet epoll_wait(iEpfd, stEpEvent, 1, -1);if (iRet 0){s eventfd_read(iEvtfd, uiRead);if (s ! 0){printf(read iEvtfd failed\n);break;}printf(Read %llu (0x%llx) from iEvtfd\n, uiRead, uiRead);}}close(g_iEvtfd);close(iEpfd);return 0; }运行结果 kanekanelinux:/mnt/hgfs/kanelinuxshare/eventfd$ ./a.out Read 1 (0x1) from iEvtfd Read 1 (0x1) from iEvtfdRead 1 (0x1) from iEvtfd Read 1 (0x1) from iEvtfdRead 1 (0x1) from iEvtfd Read 1 (0x1) from iEvtfdRead 1 (0x1) from iEvtfd Read 1 (0x1) from iEvtfd^C 例一中并没有epoll做监控 因此在read前如果eventfd被写多次在read的时候也是一次全部读出。 注eventfd中的SEMAPHORE标志用法 * If EFD_SEMAPHORE was not specified and the eventfd counter has a nonzero value, then a read(2) returns 8 bytes contain‐ ing that value, and the counters value is reset to zero. * If EFD_SEMAPHORE was specified and the eventfd counter has a nonzero value, then a read(2) returns 8 bytes containing the value 1, and the counters value is decremented by 1. 通过测试发现。如果eventfd在创建的时候传入EFD_SEMAPHORE 标志则会按上面man手册中提到的那样每次在eventfd_read的时候只减一并不是把值一次性全部读出。见下例
http://www.pierceye.com/news/261597/

相关文章:

  • 手机刷网站排名软件建设银行网站怎么登录密码忘了怎么办
  • 利用海康威视做直播网站鞍山网站建设找金航
  • 做网站大概花多少钱商圈云分销软件下载
  • 万户网站制作网站跳转怎么做
  • 网站开发全程设计做网站推广的公司发展前景
  • 电商设计网站培训建设网站域名
  • 石家庄免费专业做网站网站建设投标书服务方案范本
  • 怀孕单子图片在线制作北京seo服务行者
  • 网站备案 子域名云南商城网站建设
  • 上传到服务器的网站打开是空白网站报备流程
  • 如何用ps做网站标识一个叫mit做app的网站
  • 网站免费网站免费主流网站模板
  • 湖州市交通建设管理局网站牌具做网站可以吗
  • 湖南鸿泰电力建设有限公司网站西安做小程序的公司
  • 学校资源网站建设方案聊城网站建设
  • windows 做网站服务器python做的网站漏洞
  • 培训网站推荐网站内容该怎么做
  • 精通网站建设电子档朵朵软件网站建设
  • 铜山区规划建设局网站网站开发的甘特图
  • 访问网站速度慢中国最新军事新闻直播
  • 商城网站的psd模板免费下载哪里可以上传自己的php网站
  • 珠宝网站策划书网页设计的毕业设计
  • 最经典最常用的网站推广方式什么做网站赚钱
  • 广州哪家做网站化妆品网站方案
  • cms开源网站管理系统北京网站建设策划解决方案
  • 洛阳做多屏合一网站最新款淘宝客源码整网站程序模板+后台带自动采集商品功能带文章
  • 宁国新站seo中国建筑网官网监理工程师网站
  • 自己建网站多少钱福州建设企业网站
  • 容桂佛山做app网站wordpress 搜索 任意
  • dw做单页网站教程盐城网站建设价位