For Developers‎ > ‎Design Documents‎ > ‎Mojo‎ > ‎

Synchronous Calls

Think carefully before you decide to use sync calls

Although sync calls are convenient, you should avoid them whenever they are not absolutely necessary:
  • Sync calls hurt parallelism and therefore hurt performance.
  • Re-entrancy changes message order and produces call stacks that you probably never think about while you are coding. It has always been a huge pain.
  • Sync calls may lead to deadlocks.

Mojom

A new attribute [Sync] (or [Sync=true]) is introduced for methods. For example:
 
 
interface Foo {
  [Sync]
  SomeSyncCall() => (Bar result);
};
 
It indicates that when SomeSyncCall() is called, the control flow of the calling thread is blocked until the response is received.
 
It is not allowed to use this attribute with functions that don’t have responses. If you just need to wait until the service side finishes processing the call, you can use an empty response parameter list:
 
[Sync]
SomeSyncCallWithNoResult() => ();
 

Generated bindings (C++)

The generated C++ interface of the Foo interface above is:
 
class Foo {
 public:
  // The service side implements this signature. The client side can also use this signature if it wants to call the method asynchronously.
  virtual void SomeSyncCall(SomeSyncCallCallback callback) = 0;

  // The client side uses this signature to call the method synchronously.
  virtual bool SomeSyncCall(BarPtr* result);
};
 
 
As you can see, the client side and the service side use different signatures. At the client side, response is mapped to output parameters and the boolean return value indicates whether the operation is successful. (Returning false usually means a connection error has occurred.)
 
At the service side, a signature with callback is used. The reason is that in some cases the implementation may need to do some asynchronous work which the sync method’s result depends on.
 
Note: you can also use the signature with callback at the client side to call the method asynchronously.

Re-entrancy

What happens on the calling thread while waiting for the response of a sync method call? It continues to process incoming sync request messages (i.e., sync method calls); block other messages, including async messages and sync response messages that don’t match the ongoing sync call.

 
 
 
Please note that sync response messages that don’t match the ongoing sync call cannot re-enter. That is because they correspond to sync calls down in the call stack. Therefore, they need to be queued and processed while the stack unwinds.

Avoid deadlocks

Please note that the re-entrancy behavior doesn’t prevent deadlocks involving async calls. You need to avoid call sequences such as:
 
 

Read more

[Chromium文档转载,第004章]Mojo Synchronous Calls的更多相关文章

  1. [Chromium文档转载,第003章]Proposal: Mojo Synchronous Methods

    Proposal: Mojo Synchronous Methods yzshen@chromium.org 02/02/2016 Overview Currently there are quite ...

  2. [Chromium文档转载,第002章]Mojo C++ Bindings API

    Mojo C++ Bindings API This document is a subset of the Mojo documentation. Contents Overview Getting ...

  3. [Chromium文档转载,第006章]Chrome IPC To Mojo IPC Cheat Sheet

    For Developers‎ > ‎Design Documents‎ > ‎Mojo‎ > ‎ Chrome IPC To Mojo IPC Cheat Sheet 目录 1 O ...

  4. [Chromium文档转载,第001章] Mojo Migration Guide

        For Developers‎ > ‎Design Documents‎ > ‎Mojo‎ > ‎ Mojo Migration Guide 目录 1 Summary 2 H ...

  5. [Chromium文档转载,第005章]Calling Mojo from Blink

    For Developers‎ > ‎Design Documents‎ > ‎Mojo‎ > ‎ Calling Mojo from Blink Variants Let's as ...

  6. [Chromium文档转载,第007章]JNI on Chromium for Android

    Overview JNI (Java Native Interface) is the mechanism that enables Java code to call native function ...

  7. 用R创建Word和PowerPoint文档--转载

    https://www.jianshu.com/p/7df62865c3ed Rapp --简书 Microsoft的Office软件在办公软件领域占有绝对的主导地位,几乎每个职场人士都必须掌握Wor ...

  8. java实现支付宝接口--文档..转载

    //实现java支付宝很简单,只要从支付宝官方下载   http://help.alipay.com/support/index_sh.htm下载程序,配置一下参数就OK了:   1.先到http:/ ...

  9. iOS开发主要参考文档(转载)

    Objective-C,语言的系统详细资料.这是做iOS开发的前题与基础.https://developer.apple.com/library/ios/#documentation/Cocoa/Co ...

随机推荐

  1. cogs 181. [USACO Jan07] 最高的牛

    181. [USACO Jan07] 最高的牛 ★★   输入文件:tallest.in   输出文件:tallest.out   简单对比时间限制:1 s   内存限制:32 MB FJ's N ( ...

  2. Qt之QNetworkProxy(网络代理)

    简述 QNetworkProxy类提供了一个网络层代理. QNetworkProxy提供了配置网络层代理支持Qt网络类的方法.目前支持的类有QAbstractSocket.QTcpSocket.QUd ...

  3. Android体验高扩展艺术般的适配器

    前言 本篇文章带大家体验一下一种具有扩展性的适配器写法. 这个适配器主要用于Item有多种的情况下.当然仅仅有一种类型也是适用的 实现 毫无疑问我们要继承BaseAdapter,重写getCount, ...

  4. iOS 9 适配,我咋还没遇到这么多坑呢呀

    iOS 9 适配,我咋还没遇到这么多坑呢呀 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 ...

  5. STL源代码学习(vector篇)

    #include <concept_checks.h> #include<stl_allocate.h> /// The vector base class's constru ...

  6. 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记3 Xcode、Auto Layout及MVC

    继续上一话中的计算器Demo.上一话讲到类必须被初始化.类中的属性也必须被初始化,所以你不能仅仅声明而不给它一个处置,那么问题来了,我们从storyboard中拖拽的@IBOutlet为什么仅仅有声明 ...

  7. [luogu P3360] 偷天换日 解题报告(树形DP)

    题目链接:https://www.luogu.org/problemnew/show/P3360 题解: 首先我们把边上的消耗放到向下的点上,如果是叶子节点的话就先做一次0/1背包 发现这是一颗二叉树 ...

  8. Pycharm-连接服务器

  9. Hadoop的目录结构

  10. java9新特性-12-集合工厂方法:快速创建只读集合

    1.官方Feature 269: Convenience Factory Methods for Collections 2.产生背景 要创建一个只读.不可改变的集合,必须构造和分配它,然后添加元素, ...