�������� ��������������� ������� �������� ��������� .NET

Serhiy Yaroshko, S. Yaroshko
{"title":"�������� ��������������� ������� �������� ��������� .NET","authors":"Serhiy Yaroshko, S. Yaroshko","doi":"10.30970/vam.2019.27.10137","DOIUrl":null,"url":null,"abstract":"The majority of modern software applications make use of several execution threads. For example, in the text editor, one thread is responsible for the spell cheking, another for autosaving, one more thread for handling the user input. The mechanism of multiple threads provides the software developer with a convenient way of structuring the functional possibilities: the software application architecture will be more stable, if it's various possibilities are programmed separately from each other. The ability to use multiple threads will be useful even for a specialist of numerical computing. The iteration methods usually need to execute a large amount of computations in order to receive an approximate solution of a certain problem. This circumstance should be taken into account at the stage of software design architecture so, that a user could follow the computational process and not worry about the responsiveness of the application. In order to launch a separate execution thread, the .Net framework provides a developer with an eective template of task-based asynchronous programming [3] that uses some new keywords async, await and classes Task, Task from the namespace System.Threading.Tasks. The instances of this class are created very fast, they need only a little amount of system resources and they eectively use the processors time. That's why it is convenient to move the computations to a separate thread, which on its turn can also launch dierent parallel computational threads. This approach signicantly accelerates a software performance on a multiprocessor (or multi-core) computer. The keyword async in the name of an asynchronous method changes the way of how the result of this method is handled, and gives a possibility to use the instruction await for launching any awaitable object. For this purpose, in the .Net framework there are usually used the instances of the classes Task and Task . The task, launched with the instruction await, does not block the user interface thread during the computation. Before launching an synchronous task, there are dierent preparation steps: create a stop-marker CancellationToken token, an object Progress progress in order to be able to send the data to the main thread, and nally a set of local variables to correctly catch the execution context. Then the asynchronous method in the right moment calls progress.Report(data), for a \"soft\" termination of an asynchronous algorithm. In a convenient point in time, this algorithm should check the property token.IsCancellationRequested and terminate the execution on request. The cancellation request can be initiated from the main thread by calling the method token.Cancel(). In order to synchronize the nishing of the array of asynchronous tasks, the static method Task.WhenAll(tasks).Wait() is used. For the demonstration of the described approaches an application has been created. It demonstrates how to apply the genetic algorithm in order to solve the traveling sales-man problem [6] for a large number of cities. It is experimentally analyzed how the number of threads inuences the performance of the application. The complete code base can be downloaded from the repository [4].","PeriodicalId":302104,"journal":{"name":"Application Mathematics and Informatics","volume":"25 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2020-03-05","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"2","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Application Mathematics and Informatics","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.30970/vam.2019.27.10137","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 2

Abstract

The majority of modern software applications make use of several execution threads. For example, in the text editor, one thread is responsible for the spell cheking, another for autosaving, one more thread for handling the user input. The mechanism of multiple threads provides the software developer with a convenient way of structuring the functional possibilities: the software application architecture will be more stable, if it's various possibilities are programmed separately from each other. The ability to use multiple threads will be useful even for a specialist of numerical computing. The iteration methods usually need to execute a large amount of computations in order to receive an approximate solution of a certain problem. This circumstance should be taken into account at the stage of software design architecture so, that a user could follow the computational process and not worry about the responsiveness of the application. In order to launch a separate execution thread, the .Net framework provides a developer with an eective template of task-based asynchronous programming [3] that uses some new keywords async, await and classes Task, Task from the namespace System.Threading.Tasks. The instances of this class are created very fast, they need only a little amount of system resources and they eectively use the processors time. That's why it is convenient to move the computations to a separate thread, which on its turn can also launch dierent parallel computational threads. This approach signicantly accelerates a software performance on a multiprocessor (or multi-core) computer. The keyword async in the name of an asynchronous method changes the way of how the result of this method is handled, and gives a possibility to use the instruction await for launching any awaitable object. For this purpose, in the .Net framework there are usually used the instances of the classes Task and Task . The task, launched with the instruction await, does not block the user interface thread during the computation. Before launching an synchronous task, there are dierent preparation steps: create a stop-marker CancellationToken token, an object Progress progress in order to be able to send the data to the main thread, and nally a set of local variables to correctly catch the execution context. Then the asynchronous method in the right moment calls progress.Report(data), for a "soft" termination of an asynchronous algorithm. In a convenient point in time, this algorithm should check the property token.IsCancellationRequested and terminate the execution on request. The cancellation request can be initiated from the main thread by calling the method token.Cancel(). In order to synchronize the nishing of the array of asynchronous tasks, the static method Task.WhenAll(tasks).Wait() is used. For the demonstration of the described approaches an application has been created. It demonstrates how to apply the genetic algorithm in order to solve the traveling sales-man problem [6] for a large number of cities. It is experimentally analyzed how the number of threads inuences the performance of the application. The complete code base can be downloaded from the repository [4].
大多数现代软件应用程序使用多个执行线程。例如,在文本编辑器中,一个线程负责拼写检查,另一个线程负责自动保存,还有一个线程负责处理用户输入。多线程机制为软件开发人员提供了一种方便的构造功能可能性的方法:如果将各种可能性彼此分开编程,软件应用程序体系结构将更加稳定。使用多线程的能力甚至对数值计算专家也很有用。为了得到某一问题的近似解,迭代法通常需要执行大量的计算。在软件设计架构阶段应该考虑到这种情况,这样用户就可以遵循计算过程,而不必担心应用程序的响应性。为了启动一个单独的执行线程,. net框架为开发人员提供了一个有效的基于任务的异步编程模板[3],该模板使用了一些新的关键字async, await和类Task, Task来自命名空间System.Threading.Tasks。该类的实例创建非常快,它们只需要少量的系统资源,并且有效地使用处理器时间。这就是为什么将计算移动到一个单独的线程是方便的,而这个线程又可以启动不同的并行计算线程。这种方法显著地加速了多处理器(或多核)计算机上的软件性能。异步方法名称中的关键字async改变了如何处理该方法的结果,并提供了使用指令await来启动任何可等待对象的可能性。为此,在。net框架中,通常使用Task和Task类的实例。使用await指令启动的任务在计算期间不会阻塞用户界面线程。在启动同步任务之前,有不同的准备步骤:创建一个停止标记CancellationToken令牌,一个对象Progress Progress以便能够将数据发送到主线程,最后是一组本地变量以正确捕获执行上下文。然后,异步方法在适当的时候调用progress.Report(data),以“软”终止异步算法。在一个方便的时间点,该算法应该检查属性令牌。IsCancellationRequested并在请求时终止执行。可以通过调用token.Cancel()方法从主线程发起取消请求。为了同步异步任务数组的完成,使用静态方法Task.WhenAll(tasks). wait()。为了演示所描述的方法,已经创建了一个应用程序。它演示了如何应用遗传算法来解决大量城市的旅行推销员问题[6]。通过实验分析了线程数对应用程序性能的影响。完整的代码库可以从存储库中下载[4]。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信