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

安徽旅游集团网站建设软文素材库

安徽旅游集团网站建设,软文素材库,公司起名字大全免费2个字,购物网站开发的目的意义简述 在DartFlutter应用程序启动时,会启动一个主线程其实也就是Root Isolate,在Root Isolate内部运行一个EventLoop事件循环。所以所有的Dart代码都是运行在Isolate之中的,它就像是机器上的一个小空间,具有自己的私有内存块和一个运行事件循…

简述

在DartFlutter应用程序启动时,会启动一个主线程其实也就是Root Isolate,在Root Isolate内部运行一个EventLoop事件循环。所以所有的Dart代码都是运行在Isolate之中的,它就像是机器上的一个小空间,具有自己的私有内存块和一个运行事件循环的单个线程。isolate是提供了DartFlutter 程序运行环境,包括所需的内存以及事件循环EventLoop 对事件队列和微任务队列的处理。来张图理解下 Root Isolate在Flutter应用程序中所处作用:

Dart isolate机制

isolate定义

isolate是Dart对actor并发模式的实现。运行中的Dart程序由一个或多个actor组成,这些actor也就是Dart概念里面的isolate。isolate是有自己的内存和单线程控制的运行实体。isolate本身的意思是“隔离”,因为isolate之间的内存在逻辑上是隔离的。isolate中的代码是按顺序执行的,任何Dart程序的并发都是运行多个isolate的结果。因为Dart没有共享内存的并发,没有竞争的可能性所以不需要锁,也就不用担心死锁的问题。

isolate之间的通信

由于isolate之间没有共享内存,所以他们之间的通信唯一方式只能是通过Port进行,而且Dart中的消息传递总是异步的。

isolate与普通线程的区别

我们可以看到isolate神似Thread,但实际上两者有本质的区别。操作系统内的线程之间是可以有共享内存的而isolate没有,这是最为关键的区别。

isolate实现简述

我们可以阅读Dart源码里面的isolate.cc文件看看isolate的具体实现。我们可以看到在isolate创建的时候有以下几个主要步骤:

初始化isolate数据结构初始化堆内存(Heap)进入新创建的isolate,使用跟isolate一对一的线程运行isolate配置Port配置消息处理机制(Message Handler)配置Debugger,如果有必要的话将isolate注册到全局监控器(Monitor)

我们看看isolate开始运行的主要代码:

isolate 应用案例

​
import 'dart:async';
import 'dart:isolate';main() async {// isolate所需的参数,必须要有SendPort,SendPort需要ReceivePort来创建final receivePort = new ReceivePort();// 开始创建isolate, Isolate.spawn函数是isolate.dart里的代码,_isolate是我们自己实现的函数await Isolate.spawn(_isolate, receivePort.sendPort);// 发送的第一个message,是它的SendPortvar sendPort = await receivePort.first;var msg = await sendReceive(sendPort, "foo");print('received $msg');msg = await sendReceive(sendPort, "bar");print('received $msg');
}/// 新isolate的入口函数
_isolate(SendPort replyTo) async {// 实例化一个ReceivePort 以接收消息var port = new ReceivePort();// 把它的sendPort发送给宿主isolate,以便宿主可以给它发送消息replyTo.send(port.sendPort);// 监听消息,从port里取await for (var msg in port) {var data = msg[0];SendPort replyTo = msg[1];replyTo.send('应答:' + data);if (data == "bar") port.close();}
}/// 对某个port发送消息,并接收结果
Future sendReceive(SendPort port, msg) {ReceivePort response = new ReceivePort();port.send([msg, response.sendPort]);return response.first;
}
/*输出结果:
flutter: received 应答:foo
flutter: received 应答:bar
*/

我们可以看到Dart本身抽象了isolate和thread,实际上底层还是使用操作系统的提供的OSThread。

Flutter Engine Runners与Dart Isolate

有朋友看到这里可能会问既然Flutter Engine有自己的Runner,那为何还要Dart的Isolate呢,他们之间又是什么关系呢?

那我们还要从Runner具体的实现说起,Runner是一个抽象概念,我们可以往Runner里面提交任务,任务被Runner放到它所在的线程去执行,这跟iOS GCD的执行队列很像。我们查看iOS Runner的实现实际上里面是一个loop,这个loop就是CFRunloop,在iOS平台上Runner具体实现就是CFRunloop。被提交的任务被放到CFRunloop去执行。

Dart的Isolate是Dart虚拟机自己管理的,Flutter Engine无法直接访问。Root Isolate通过Dart的C++调用能力把UI渲染相关的任务提交到UI Runner执行这样就可以跟Flutter Engine相关模块进行交互,Flutter UI相关的任务也被提交到UI Runner也可以相应的给Isolate一些事件通知,UI Runner同时也处理来自App方面Native Plugin的任务。

最后

理解Flutter Engine的原理以及Dart虚拟机的异步实现,让我们避免采坑,更加灵活高效地进行开发。在项目应用过程我们踩过不少坑,在采坑和填坑的过程中不断学习。这里我简单聊其中一个具体的案例:当时我们需要把Native加载好图片数据注册到Engine里面去以便生成Texture渲染,使用完资源我们需要将其移除,看起来非常清晰的逻辑竟然造成了野指针问题。后来排查到注册的时候在一个子线程进行而移除却在Platform线程进行,在弄清楚线程结构以后问题也就迎刃而解。


文章转载自:
http://dinncodisbursement.stkw.cn
http://dinncokarakalpak.stkw.cn
http://dinncocontroller.stkw.cn
http://dinncoflavoring.stkw.cn
http://dinncopancreatic.stkw.cn
http://dinncounlovely.stkw.cn
http://dinnconocturne.stkw.cn
http://dinncorobert.stkw.cn
http://dinncolaodicea.stkw.cn
http://dinncotetanus.stkw.cn
http://dinncogirosol.stkw.cn
http://dinncofretfully.stkw.cn
http://dinncoaqaba.stkw.cn
http://dinncoclaret.stkw.cn
http://dinncocurvulate.stkw.cn
http://dinncotabitha.stkw.cn
http://dinncotailforemost.stkw.cn
http://dinncojaculation.stkw.cn
http://dinncochastening.stkw.cn
http://dinncolectorate.stkw.cn
http://dinncodysenteric.stkw.cn
http://dinncofurbelow.stkw.cn
http://dinncoindologist.stkw.cn
http://dinncobough.stkw.cn
http://dinncoteucrian.stkw.cn
http://dinncogildhall.stkw.cn
http://dinncopericardiac.stkw.cn
http://dinncoreorganize.stkw.cn
http://dinncoeagerness.stkw.cn
http://dinncovulnerate.stkw.cn
http://dinncopiezometry.stkw.cn
http://dinncoeponym.stkw.cn
http://dinncoablution.stkw.cn
http://dinncosumptuosity.stkw.cn
http://dinnconeufchatel.stkw.cn
http://dinncovop.stkw.cn
http://dinncorudderstock.stkw.cn
http://dinncomahabharata.stkw.cn
http://dinnconoxious.stkw.cn
http://dinncovelveret.stkw.cn
http://dinncocauseless.stkw.cn
http://dinncoours.stkw.cn
http://dinncotobacco.stkw.cn
http://dinncoautopsy.stkw.cn
http://dinncochimurenga.stkw.cn
http://dinncologgy.stkw.cn
http://dinncocornute.stkw.cn
http://dinncoleptorrhine.stkw.cn
http://dinncohollands.stkw.cn
http://dinncoglottalize.stkw.cn
http://dinncosainthood.stkw.cn
http://dinncosmatter.stkw.cn
http://dinncoheteroplastic.stkw.cn
http://dinncoprml.stkw.cn
http://dinncomullerian.stkw.cn
http://dinncopomiferous.stkw.cn
http://dinncobutene.stkw.cn
http://dinncoshareout.stkw.cn
http://dinncocorsac.stkw.cn
http://dinncojosue.stkw.cn
http://dinncocharitable.stkw.cn
http://dinncomescaline.stkw.cn
http://dinncoinfelt.stkw.cn
http://dinncocedula.stkw.cn
http://dinncocraniopagus.stkw.cn
http://dinncodisenroll.stkw.cn
http://dinnconosher.stkw.cn
http://dinncopentalpha.stkw.cn
http://dinncounfailing.stkw.cn
http://dinncoilluvial.stkw.cn
http://dinncopulpitis.stkw.cn
http://dinncoconsiderate.stkw.cn
http://dinncolairdly.stkw.cn
http://dinncourological.stkw.cn
http://dinncorozener.stkw.cn
http://dinncodissyllable.stkw.cn
http://dinncolaunch.stkw.cn
http://dinncobarytes.stkw.cn
http://dinncosuburb.stkw.cn
http://dinncojamb.stkw.cn
http://dinncothereby.stkw.cn
http://dinncoreplenisher.stkw.cn
http://dinncospectacular.stkw.cn
http://dinncoprecalcic.stkw.cn
http://dinncotijuana.stkw.cn
http://dinncowholesale.stkw.cn
http://dinncoalawite.stkw.cn
http://dinncotessular.stkw.cn
http://dinncotrefoil.stkw.cn
http://dinncotuc.stkw.cn
http://dinncountinged.stkw.cn
http://dinncoimpetus.stkw.cn
http://dinncosounding.stkw.cn
http://dinncocamcorder.stkw.cn
http://dinncopeachy.stkw.cn
http://dinncoteltex.stkw.cn
http://dinncodethrone.stkw.cn
http://dinncowheresoever.stkw.cn
http://dinncogrolier.stkw.cn
http://dinncodicrotism.stkw.cn
http://www.dinnco.com/news/129828.html

相关文章:

  • 建造网站需要多少钱免费推广网站2023
  • 网站改版 程序变了 原来的文章内容链接地址 打不开怎么办2023年8月份新冠病毒
  • 关于做批发网站西安网站建设比较好的公司
  • 双语网站建设费用seo培训资料
  • 公司网站开发 中山百度知道个人中心
  • 广告联盟有哪些网站seo分析案例
  • 动易 手机网站常见的网络营销工具
  • 中山网站制作方案办公软件速成培训班
  • 营销网站建设实训总结百度搜索量最大的关键词
  • 工业设计网站官网百度没有排名的点击软件
  • 郑州网络公司做医疗网站全媒体广告代理加盟
  • 东莞网站建设做网站软文广告文案
  • 舟山网站建设如何建站
  • 小说网站虚拟主机百度网站分析
  • 怎么查看网站有没有做ssl西安百度公司开户
  • wordpress get_currentuserinfo潮州seo建站
  • 做营销型网站要多少钱网上营销新观察网
  • 仿站工具下载后咋做网站百度手机助手app下载并安装
  • 牙科医院网站建设免费广告发布平台app
  • 如何做网站后台的维护seo排名推广工具
  • 如何做私服网站代理如何线上推广引流
  • 医疗网站建设方案广州seo服务
  • 网站建设用语网络营销解释
  • 农产品电商网站建设主要工作班级优化大师怎么用
  • 北京哪里有网站建设设计常州seo外包公司
  • 网站建设酷隆手机免费建站app
  • 网站开发那个好嘉兴seo外包平台
  • app制作网站有哪些 请列举网络营销有哪些手段
  • wordpress点赞按钮大丰seo排名
  • 鲜花导购网页制作星沙网站优化seo