77范文网 - 专业文章范例文档资料分享平台

Safe Concurrent Programming in Java

来源:网络收集 时间:2021-04-05 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

Multithreaded programming is difficult and error prone. Multithreaded programs typically synchronize operations on shared mutable data to ensure that the operations execute

Chandrasekhar Boyapati CHANDRA@LCS.MIT.EDU Robert Lee RHLEE@LCS.MIT.EDU Martin Rinard RINARD@LCS.MIT.EDU MIT Laboratory for Computer Science,200Technology Square,Cambridge MA,02139USA

1.Introduction

Multithreaded programming is dif?cult and error prone. Multithreaded programs typically synchronize operations on shared mutable data to ensure that the operations exe-cute atomically.Failure to correctly synchronize such op-erations can lead to data races or deadlocks.A data race occurs when two threads concurrently access the same data without synchronization,and at least one of the accesses is a write.A deadlock occurs when there is a cycle of the form:,Thread holds Lock and Thread is waiting for Lock.

This paper presents a new static type system for multi-threaded programs;well-typed programs in our system are guaranteed to be free of data races and deadlocks.In recent previous work,we presented a static type system to prevent data races.In this paper,we extend the race-free type sys-tem to prevent both data races and deadlocks.The basic idea behind our system is as follows.When programmers write multithreaded programs,they already have a lock-ing discipline in mind.Our system allows programmers to specify this locking discipline in their programs.The resulting speci?cations take the form of type declarations. To prevent data races,programmers associate every object with a protection mechanism that ensures that accesses to the object never create data races.The protection mecha-nism of an object can specify either the mutual exclusion lock that protects the object from unsynchronized concur-rent accesses,or that threads can safely access the object without synchronization because either1)the object is im-mutable,2)the object is accessible to a single thread,or 3)the variable contains the unique pointer to the object. Unique pointers are useful to support object migration be-tween threads.The type checker statically veri?es that a program uses objects only in accordance with their de-clared protection mechanisms.

To prevent deadlocks,programmers partition all the locks into a?xed number of lock levels and specify a partial order among the lock levels.The type checker statically veri?es that whenever a thread holds more than one lock,the thread acquires the locks in the descending order.Our system also allows programmers to use recursive tree-based data struc-tures to further order the locks that belong to the same lock level.For example,programmers can specify that nodes in a tree must be locked in the tree-order.Our system allows mutations to the data structure that change the partial order at runtime.The type checker uses an intra-procedural intra-loop?ow-sensitive analysis to statically verify that the mu-tations do not introduce cycles in the partial order,and that the changing of the partial order does not lead to deadlocks. Although our type system is explicitly typed in principle,it would be onerous to fully annotate every method with the extra type information that our system requires.Instead, we use a combination of intra-procedural type inference and well-chosen defaults to signi?cantly reduce the num-ber of annotations needed in practice.Our approach per-mits separate compilation.We have a prototype implemen-tation of our type system that handles all the features of the Java language.We also modi?ed several multithreaded Java programs and implemented them in our system.These programs exhibit a variety of sharing patterns.Our expe-rience shows that our system is suf?ciently expressive and requires little programming overhead.

2.The Type System

This section introduces our type system with two examples. Figure1presents an example program that has an Account class and a CombinedAccount class.To prevent data races,programmers associate every object with a protec-tion mechanism.In the example,the CombinedAccount class is declared to be immutable.A CombinedAccount may not be modi?ed after initialization.The Account class is generic—different Account objects may have dif-ferent protection mechanisms.The CombinedAccount class contains two Account?elds—savingsAccount and checkingAccount.The key word self indicates that these two Account objects are protected by their own locks.The type checker statically ensures that a thread holds the locks on these Account objects before accessing the Account objects.

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库Safe Concurrent Programming in Java在线全文阅读。

Safe Concurrent Programming in Java.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/1205438.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: