Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019-10-23:请谈谈什么是同步屏障? #171

Open
Moosphan opened this issue Oct 23, 2019 · 6 comments
Open

2019-10-23:请谈谈什么是同步屏障? #171

Moosphan opened this issue Oct 23, 2019 · 6 comments
Labels

Comments

@Moosphan
Copy link
Owner

No description provided.

@DaveBoy
Copy link

DaveBoy commented Oct 23, 2019

停止同步消息的处理,只处理异步消息,一般异步消息为系统的某些事件

@arjun512
Copy link

高大上的名词

@zkHuang
Copy link

zkHuang commented Oct 29, 2019

高大上的名词

同解。

@icytz
Copy link

icytz commented Nov 27, 2019

handler.getLooper().getQueue().postSyncBarrier()加入同步屏障后,Message.obtain()获取一个target为null的msg,并根据当前时间将该msg插入到链表中。
在Looper.loop()循环取消息中 Message msg = queue.next(); target为空时,取链表中的异步消息。
通过setAsynchronous(true)来指定为异步消息

应用场景:ViewRootImpl scheduleTraversals中加入同步屏障 并在view的绘制流程中post异步消息,保证view的绘制消息优先执行

@aositeluoke
Copy link

  • 我们平时使用Handler发送的消息都是普通消息, 同步屏障不会唤醒消息队列
  • 同步屏障没有target,因为它不需要分发
  • 它的主要作用在于挡住同步消息,只允许程序处理异步消息,保证异步消息能够优先处理

参考文章

Handler机制——同步屏障

@mlinqirong
Copy link

Handler 的消息发送有三种
普通消息
异步消息
屏障消息
发送了屏障消息后 不接收同步消息,只允许接收异步消息

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants