Learn TLA+

栏目: IT技术 · 发布时间: 6年前

内容简介:I now have abook available! You can check it outTLA+ is aHere’s a simple TLA+ specification, representing people trading unique items. Can you find the bug?

Introduction

I now have abook available! You can check it out here and read more about ithere.

What is TLA+?

TLA+ is a formal specification language . It’s a tool to design systems and algorithms, then programmatically verify that those systems don’t have critical bugs. It’s the software equivalent of a blueprint.

Why should I use it?

Here’s a simple TLA+ specification, representing people trading unique items. Can you find the bug?

People == {"alice", "bob"}
Items == {"ore", "sheep", "brick"}
(* --algorithm trade
variable owner_of \in [Items -> People]

process giveitem \in 1..3 \* up to three possible trades made
variables item \in Items, 
          owner = owner_of[item], 
          to \in People,
          origin_of_trade \in People
begin Give:
    if origin_of_trade = owner then 
        owner_of[item] := to;
    end if;
end process;
end algorithm; *)

Since we check that the owner of an item is the one trading it away, we should be safe against scams, right? But if we run the model checker, we find that’s not true: Alice could trade an item to herself and, before that process finishes running, resolve a parallel trade giving that same item to Bob. Then the first trade resolves and Alice gets the item back. Our algorithm fails for race conditions, and we know this because TLA+ explored every possible state and timeline.

There’s a few different ways of fixing this. But does our fix work for more than two people? In TLA+, checking that is as simple as People == {"alice", "bob", "eve"} . Does it work if we can trade multiple items at once? variable items \in SUBSET Items . What about if there’s multiple sheep, ore, and bricks? amount_owned = [People \X Items -> 0..5] . What if three people are all trading 1 ore and 1 sheep with each of the other players while Eve also trades Alice 0 brick? If it’s in the possible state space, TLA+ will check it.

Is it hard to use?

Formal methods have a reputation for being difficult to the point where they’re only worth it for critical systems. This means that all of the guides are written under the assumption that the reader is working on a critical system, where they have to know TLA+ inside and out to make absolutely sure that their system won’t accidentally kill people .

If a dangerous bug to you is “somebody dies”, then yes, formal methods are hard. If a dangerous bug to you is “nobody dies but our customers get really mad and we have to spend two weeks tracking down and fixing the bug”, then the small subset of TLA+ you’ll need is actually pretty easy to learn. Just find a beginner-friendly guide and you’re all set.

Where’s a beginner-friendly guide?

Hello! This guide covers the basics of TLA+ in an easy, hands-on way. If you want to start from the beginning, you can learn more about what we’ll coverhere. If you want to dive in right away, why not try awhirlwind tour?

Either way, welcome to TLA+!


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

刷新

刷新

[美] 萨提亚·纳德拉 / 陈召强、杨洋 / 中信出版集团 / 2018-1 / 58

《刷新:重新发现商业与未来》是微软CEO萨提亚•纳德拉首部作品。 互联网时代的霸主微软,曾经错失了一系列的创新机会。但是在智能时代,这家科技公司上演了一次出人意料的“大象跳舞”。2017年,微软的市值已经超过6000亿美元,在科技公司中仅次于苹果和谷歌,高于亚马逊和脸谱网。除了传统上微软一直占有竞争优势的软件领域,在云计算、人工智能等领域,微软也获得强大的竞争力。通过收购领英,微软还进入社交......一起来看看 《刷新》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码