内容简介:Kotlin/Native v0.8 已正式发布,该版本有以下值得关注的更新: 更安全的并发编程 扩展 stdlib 功能 更好的 iOS 开发支持 此外该版本还包含许多错误修复和优化。 GitHub 发布主页 https://github.com/JetBrains/...
Kotlin/Native v0.8 已正式发布,该版本有以下值得关注的更新:
更安全的并发编程
扩展 stdlib 功能
更好的 iOS 开发支持
此外该版本还包含许多错误修复和优化。
GitHub 发布主页 https://github.com/JetBrains/kotlin-native/releases/tag/v0.8
更好的并发支持
在 v0.8 之前,Kotlin/Native 应用程序将单例对象状态保持为特定执行的线程的本地状态,因此不同线程上的单例对象的状态可能是非同步的。现在,扩展了冻结单例对象的概念,允许共享的不可变状态。
例如,以下代码
object Config { var width: Int = 10 private set init { val file = fopen("config.txt", "r") if (file != null) { try { memScoped { val bufferLength = 2 * 1024 val buffer = allocArray(bufferLength) while (true) { val nextLine = fgets(buffer, bufferLength, file)?.toKString() if (nextLine == null || nextLine.isEmpty()) break val records = nextLine.split('=') if (records.size != 2) continue val key = records[0].trim() val value = records[1].trim() when (key) { "width" -> width = value.toInt() } } } } finally { fclose(file) } } } }
将读取配置文件,并可以提供 Config.width 属性。 每个进程执行时将读取一次 Config 文件,并且可供任何线程或 worker 使用。 而一旦发布,该对象就会被冻结,并且不能再被修改(尝试修改将抛出 InvalidMutabilityException 异常)。
其他有关库的改进,以及对 iOS 开发支持的改进,请查看发布主页 https://blog.jetbrains.com/kotlin/2018/07/kotlinnative-v0-8-released/
【声明】文章转载自:开源中国社区 [http://www.oschina.net]
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Go并发编程-并发编程难在哪里
- Java并发编程的艺术,解读并发编程的优缺点
- Java并发系列—并发编程基础
- JAVA并发编程之并发模拟工具
- Java并发系列—并发编程的挑战
- c++并发编程—分布式编程
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms in C (Computer Science Series)
Robert Sedgewick / Addison-Wesley Professional / 1990-01-11 / USD 59.99
This new version of the best-selling book, Algorithms, SecondEdition, provides a comprehensive collection of algorithmsimplemented in C. A variety of algorithms are described in eachofthe following ar......一起来看看 《Algorithms in C (Computer Science Series)》 这本书的介绍吧!