https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • t

    Thomas

    10/18/2019, 8:49 PM
    How can you access
    kDTLSProtocol12
    from Kotlin/Native? I am able to find
    kDTLSProtocol1
    , but I really need
    kDTLSProtocol12
    . This one is visible: https://developer.apple.com/documentation/security/sslprotocol/kdtlsprotocol1?language=objc This one is NOT visible: https://developer.apple.com/documentation/security/sslprotocol/kdtlsprotocol12?language=objc
    o
    • 2
    • 2
  • f

    Fudge

    10/19/2019, 9:30 AM
    Are there any plans to provide C++ interop?
    d
    o
    +2
    • 5
    • 12
  • m

    Marcin Wisniowski

    10/19/2019, 4:10 PM
    I want to use coroutines from my Kotlin/Native project, I understand I need to add the
    kotlinx-coroutines-core-native
    dependency, but I am not sure how to do that. The
    build.gradle
    file Idea generated for me along with the project does not have a
    dependencies
    section, and if I create my own I get an error
    Could not find method implementation()
    when running Gradle sync. What's the correct way to add the dependency? I looked at the Kotlin/Native coroutines example project and it does not have the dependency in it's
    build.gradle
    so I'm not sure how it works. This is probably a stupid issue but I can't find any information on using coroutines in Kotlin/Native, except in the context of mobile development and compatibility with iOS, while my project is just a plain simple command line program.
    n
    • 2
    • 7
  • a

    adev_one

    10/20/2019, 8:15 PM
    I’m trying to publish my library using jitpack but it uses linux for CI build and prints
    Some Kotlin/Native targets cannot be built on this linux_x64 machine and are disabled:
        * In project ':summer':
            * targets 'iosArm64', 'iosX64' (can be built with a macos_x64 host)
    To hide this message, add 'kotlin.native.ignoreDisabledTargets=true' to the Gradle properties.
    on build. Can I configure jitpack to build K/N in another way or which service should I use to publish K/N artifacts?
    s
    a
    • 3
    • 5
  • x

    XQDD

    10/21/2019, 9:38 AM
    How to run an external command and get the output?
    d
    • 2
    • 1
  • a

    Andy Gibel

    10/21/2019, 7:51 PM
    So, as someone not at all familiar with how iOS packaging works, can someone point me to any article that packages a K/N library for distribution using CocoaPods instead of as a Framework? It is my (maybe flawed) understanding that these two are mutually exclusive. Is a Framework always included statically?
    k
    s
    • 3
    • 4
  • s

    Sujit

    10/21/2019, 8:17 PM
    If I want to publish the Kotlin/Native library to be used by another project (kotlin multiplatform project for example), what is the best way to publish it? The way i understand it, kotlin native would mean many different hardward architecture. So, for the dependency manager via something with
    implementation()
    on gradle, how does it resolve the architecture to download? Currently I have a publication on maven, but I'm also uploading the
    .klib
    . Is there a way to avoid that so that I won't have to upload separate publications for all the hardwares I want to support? I'm sorry this is like a long multi-question question, but I've been wrecking my brain trying to make this work... Help please.
    k
    • 2
    • 27
  • p

    Prateek Grover

    10/22/2019, 11:51 AM
    Since we can't add multiple K/N projects as dependencies in a single multiplatform project, what is the best way to achieve this. I am currently using export method to create a common framework and then using kotlin-native-cocoapods plugin to add it to the multiplatform project. However, if I use kotlin-native-cocoapods to create the framework, it is not able to combine other K/N projects. Any solution for the above?
    a
    m
    a
    • 4
    • 13
  • l

    louiscad

    10/22/2019, 7:51 PM
    Interesting commit! Kotlin only iOS and watchOS samples, with storyboard-less UIs: https://github.com/JetBrains/kotlin-native/commit/0b8066602e1310762398f03ad209fa336d7fb5c6
    👍 4
    m
    s
    j
    • 4
    • 5
  • m

    Marc Reichelt

    10/24/2019, 10:02 AM
    Hi everyone! A colleague (iOS developer) stated that Kotlin Native does not support watchOS (for the Apple Watch). Is this still true today? I saw a statement by @olonho that it wasn’t supported, nor planned 10 months ago. How about today?
    o
    • 2
    • 1
  • l

    louiscad

    10/24/2019, 10:09 AM
    @Marc Reichelt It's supported since 1.3.60 which is currently in EAP
    m
    • 2
    • 1
  • s

    S Korebrits

    10/24/2019, 2:07 PM
    Hi all, I am starting a Kotlin - Multiplatform for an Android and iOS app. I was wondering what the best way is to separate the code base in to different Repositories in stead of having 1 code base. I was thinking of having 1 Repository for the Android App and having the Shared Framework and iOS app as GitSubmodules. Even having the shared iOS code in a separate repository and using the shared framework as a CocoaPod or Swift Package.
    k
    k
    • 3
    • 18
  • s

    S Korebrits

    10/24/2019, 2:08 PM
    Git submodules can be a hassle, so I’m open for better suggestions
    m
    g
    +3
    • 6
    • 29
  • t

    Thomas

    10/24/2019, 7:59 PM
    Hi, I have the following Swift code which works as expected:
    import UIKit
    
    class ViewController: UIViewController {
        
        override func viewDidLoad() {
            super.viewDidLoad()
            let layer = createGradient()
            layer.frame = self.view.bounds
            self.view.layer.addSublayer(layer)
        }
    
        func createGradient() -> CAGradientLayer {
            let layer = CAGradientLayer()
            layer.type = kCAGradientLayerAxial
            layer.colors = [UIColor.red.cgColor, UIColor.blue.cgColor]
            return layer
        }
    }
    I would like to convert the createGradient function to Kotlin. This is what I have tried:
    import platform.QuartzCore.CAGradientLayer
    import platform.QuartzCore.kCAGradientLayerAxial
    import platform.UIKit.UIColor
    fun createGradient(): CAGradientLayer {
        val layer = CAGradientLayer()
        layer.type = kCAGradientLayerAxial
        layer.colors = listOf(UIColor.redColor.CGColor, UIColor.blueColor.CGColor)
        return layer
    }
    When using this function the layer just doesn’t appear on the screen. As if it is completely transparent. I think something could be going wrong with the colors. Could anyone here help me out?
    👀 1
    s
    • 2
    • 3
  • m

    Marc Reichelt

    10/25/2019, 5:17 PM
    Heyho! My iOS colleague wrote that he gets the following warning when importing the shared iOS framework:
    ld: warning: ignoring file .../debugFramework/SharedCode.framework/SharedCode, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64
    And indeed the debug framework only contains x86_64. I followed the tutorial on https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/01_Introduction Is there a way to build a debug framework containing both architectures (i.e. a ‘fat framework’)?
    s
    j
    m
    • 4
    • 22
  • m

    Marcin Wisniowski

    10/26/2019, 6:01 PM
    Hello, I am trying to implement a
    Lock
    class to act as a mutex, for my
    pthread
    using code. Is there any example of that? I tried to do it like ktor: https://github.com/ktorio/ktor/blob/master/ktor-utils/posix/src/io/ktor/util/LockNative.kt but it calls functions like
    ktor_mutex_create
    whose implementation I cannot find. This is my current implementation: https://pastebin.com/THbMhiqD but I'm not sure it's correct. It clearly does something right because my threads don't immediately fail now when I lock with it, but I still get Segmentation Faults sometimes and I think it may be due to my Lock implementation.
    a
    • 2
    • 8
  • a

    Andy Gibel

    10/27/2019, 2:43 AM
    Is the official iOS/Android tutorial up to date as far as anyone knows? https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/03_CreatingSharedCode
    a
    • 2
    • 5
  • j

    jimn

    10/27/2019, 9:31 AM
    does anyone have a sample kmpp with working coroutines against latest?
    l
    • 2
    • 2
  • f

    Fudge

    10/27/2019, 12:34 PM
    Is there a benefit to using kotlin native over GraalVM native image in cases where you don’t need the c interop?
    g
    j
    • 3
    • 3
  • l

    louiscad

    10/28/2019, 10:10 AM
    Is the
    allTests
    Gradle task Kotlin/Native only?
    k
    m
    • 3
    • 5
  • a

    alexcouch

    10/28/2019, 8:31 PM
    Hey loving kotlin native. I was wondering if there was any workaround to the problems with C++ interop. I read earlier this morning that back in march of 2018 on the kotlin forums, contributer msink had stated "Kotlin/Native does not support C++ libraries, only C and Objective-C. It’s possible in theory, but hard to implement, and currently no plans for this." I was wondering what the plans are now. My static library has simple c++ use but I can easily change it to C since I'm using flex/bison to generate some C++ code for lexer and parser code, it seems to work better with C. I only have it generating C++ code because I would like to utilize C++ classes for what I would think is better interop from kotlin to C++. Is there any way I can have a C++ lib in a kotlin native project or do I need to pretty much convert my currently minimal C++ library. However the generated code is C++ but flex/bison can always regen in C.
    k
    b
    m
    • 4
    • 8
  • m

    Marc Reichelt

    10/29/2019, 8:18 PM
    Hey there! So a colleague tried out the ktor call I implemented in the
    SharedCode
    framework, but he got a crash with EXC_BAD_ACCESS. So what happened here? It looks like a bug in coroutines, but I don’t know. How do we debug crashes like this, and most importantly: how do we fix it?
    k
    • 2
    • 26
  • a

    andreasmattsson

    10/30/2019, 10:56 AM
    Could someone please explain this difference in behavior between JVM and KN (iOS) (see snippet)? Called on JVM like (Kotlin - calling multiplatform library included as gradle dependency):
    println("State Test")
    println("State Random inherited instance val 1: ${StateTest.InheritingSingleton.randomInstanceVal}")
    println("State Random inherited instance val 2: ${StateTest.InheritingSingleton.randomInstanceVal}")
    println("State Random inherited instance lazy 1: ${StateTest.InheritingSingleton.randomInstanceLazy}")
    println("State Random inherited instance lazy 2: ${StateTest.InheritingSingleton.randomInstanceLazy}")
    println("State Random file val 1: ${StateTest.InheritingSingleton.randomFileLevelVal}")
    println("State Random file val 2: ${StateTest.InheritingSingleton.randomFileLevelVal}")
    println("State Random file lazy 1: ${StateTest.InheritingSingleton.randomFileLevelLazy}")
    println("State Random file lazy 2: ${StateTest.InheritingSingleton.randomFileLevelLazy}")
    println("State Random independent val 1: ${StateTest.IndependentSingleton.randomSingletonSimple}")
    println("State Random independent val 2: ${StateTest.IndependentSingleton.randomSingletonSimple}")
    println("State Random independent lazy 1: ${StateTest.IndependentSingleton.randomSingletonLazy}")
    println("State Random independent lazy 2: ${StateTest.IndependentSingleton.randomSingletonLazy}")
    Called on iOS like (Swift - calling multiplatform library included as Cocoapod):
    print("State Test")
    print("State Random inherited instance val 1: \(StateTest.InheritingSingleton().randomInstanceVal)")
    print("State Random inherited instance val 2: \(StateTest.InheritingSingleton().randomInstanceVal)")
    print("State Random inherited instance lazy 1: \(StateTest.InheritingSingleton().randomInstanceLazy)")
    print("State Random inherited instance lazy 2: \(StateTest.InheritingSingleton().randomInstanceLazy)")
    print("State Random file val 1: \(StateTest.InheritingSingleton().randomFileLevelVal)")
    print("State Random file val 2: \(StateTest.InheritingSingleton().randomFileLevelVal)")
    print("State Random file lazy 1: \(StateTest.InheritingSingleton().randomFileLevelLazy)")
    print("State Random file lazy 2: \(StateTest.InheritingSingleton().randomFileLevelLazy)")
    print("State Random independent val 1: \(StateTest.IndependentSingleton().randomSingletonSimple)")
    print("State Random independent val 2: \(StateTest.IndependentSingleton().randomSingletonSimple)")
    print("State Random independent lazy 1: \(StateTest.IndependentSingleton().randomSingletonLazy)")
    print("State Random independent lazy 2: \(StateTest.IndependentSingleton().randomSingletonLazy)")
    Output on JVM:
    State Test
    StateTest init
    StateTest.InheritingSingleton init
    State Random inherited instance val 1: -14155247
    State Random inherited instance val 2: -14155247
    State Random inherited instance lazy 1: -1793673803
    State Random inherited instance lazy 2: -1793673803
    State Random file val 1: -483920171
    State Random file val 2: -483920171
    State Random file lazy 1: -1570839155
    State Random file lazy 2: -1570839155
    StateTest.IndependentSingleton init
    State Random independent val 1: -883005959
    State Random independent val 2: -883005959
    State Random independent lazy 1: -1287948357
    State Random independent lazy 2: -1287948357
    Output on iOS:
    State Test
    StateTest init
    State Random inherited instance val 1: 137897944
    StateTest init
    State Random inherited instance val 2: -1206959235
    StateTest init
    State Random inherited instance lazy 1: -695365290
    StateTest init
    State Random inherited instance lazy 2: 1274463100
    StateTest init
    State Random file val 1: -525097753
    StateTest init
    State Random file val 2: -525097753
    StateTest init
    State Random file lazy 1: -549146703
    StateTest init
    State Random file lazy 2: -549146703
    StateTest.IndependentSingleton init
    State Random independent val 1: 1573861028
    State Random independent val 2: 1573861028
    State Random independent lazy 1: -1005578215
    State Random independent lazy 2: -1005578215
    StateTest.kt
    p
    o
    • 3
    • 6
  • k

    Kris Wong

    10/30/2019, 8:00 PM
    if I have a mutable object that is "owned" by a worker, is there a way to reference it via the lambda passed to
    execute
    ?
    k
    a
    • 3
    • 127
  • p

    Prateek Grover

    10/31/2019, 11:15 AM
    Since coroutines on iOS can't be started on any other thread other than the main one, is it a good idea to still launch coroutines on the main thread, perform async operation and then again call back to main thread? Or should iOS developers completely switch to workers for the async needs. Why is this made in such a way? Why can't coroutines be launched from any other thread? Is the reason related to that other dispatch_queues do not have thread affinity (main queue is always connected to main thread) and that conflicts with the concurrency model of KN?
    k
    a
    +3
    • 6
    • 30
  • n

    Nico Buescher

    10/31/2019, 5:34 PM
    Hi all. I'm having some difficulty with debugging Kotlin/Native (1.3.50) in CLion (2019.2.5). From what I've found online, it should be as simple as setting a breakpoint and running the debug build in debug mode, but the program never breaks on the breakpoint. I haven't found any references to debugging being broken right now. I'm running on linux. Is there something obvious that I'm missing? Are there any resources that I could check out? The kotlin docs on debugging native only mention that a debug build can be created with th
    -g
    flag in CLI, but that doesn't help me with CLion. Thanks for any help.
    a
    • 2
    • 1
  • a

    Andy Gibel

    10/31/2019, 6:20 PM
    can anyone shed some light on one of the 1.3.60 changelog items for me?
    Produce native binaries directly from klibs, speeds up large project compilation (GH-3246)
    What does this mean exactly? What was the limitation in 1.3.50?
    o
    • 2
    • 2
  • c

    César

    11/01/2019, 2:18 PM
    Hi all. I'm developing a library that will be used by Android and iOS applications. When I get an exception on the KN code in my iOS app, the stacktrace is not complete which makes it difficult to troubleshoot issues. Is it possible to get a complete stacktrace? otherwise, do you have any suggestions on how to make some decent crash reports for my library? thanks!
    k
    l
    • 3
    • 9
  • a

    Adam Lusch

    11/01/2019, 4:40 PM
    Hello, is it possible to include symbols from dependencies in a shared library build on mingw? Specifically, I'm building a project
    Foo
    that has an
    api
    dependency on
    Bar
    , which as I understand it should export its symbols to consumers. However, the generated header only contains types from
    Bar
    that are referenced in the public API of
    Foo
    , and even then only as opaque pointers with no vtables. Is there a way to include the entire public API of
    Bar
    so that clients using the C API can make full use of
    Bar
    objects returned from
    Foo
    ? This seems similar to the
    export
    setting on
    framework
    builds for iOS, but I didn't see anything similar for
    sharedLib
    . Thanks!
    k
    • 2
    • 1
  • q

    Qinghua

    11/03/2019, 4:20 AM
    Hello, can anyone have some practical solutions to access & modify
    shared singleton
    between threads like iOS native
    sharedInstance
    behaviour ? I have read [CONCURRENCY.md](https://github.com/JetBrains/kotlin-native/blob/master/CONCURRENCY.md) and [IMMUTABILITY.md](https://github.com/JetBrains/kotlin-native/blob/master/IMMUTABILITY.md). However
    @threadLocal
    annotation can not share states between threads, but
    shared instance
    in iOS domain means it shared states in all threads.
    k
    o
    • 3
    • 9
Powered by Linen
Title
q

Qinghua

11/03/2019, 4:20 AM
Hello, can anyone have some practical solutions to access & modify
shared singleton
between threads like iOS native
sharedInstance
behaviour ? I have read [CONCURRENCY.md](https://github.com/JetBrains/kotlin-native/blob/master/CONCURRENCY.md) and [IMMUTABILITY.md](https://github.com/JetBrains/kotlin-native/blob/master/IMMUTABILITY.md). However
@threadLocal
annotation can not share states between threads, but
shared instance
in iOS domain means it shared states in all threads.
k

kpgalligan

11/03/2019, 4:59 AM
State visible by multiple threads will be frozen. If you need to change it you need to use atomics
https://medium.com/@kpgalligan/kotlin-native-stranger-threads-ep-2-208523d63c8f
q

Qinghua

11/03/2019, 5:37 AM
I have read this article and the
stately
library, it looks like the only way is that using
Atomics
to implement a
CopyOnWrite
data structure to share between threads. However, in iOS native solution is that using
NSMutableArray/NSMutableXXX
to share states with GCD avoiding data-race problem. The former
CopyOnWrite
solution which means more extra copy and lock/unlock operations maybe have performance issue ?
k

kpgalligan

11/03/2019, 7:28 AM
Well, will a copy-on-write with frozen state perform worse than NSMutableArray? I would assume yes. NSMutableArray is, as far as I know, not thread safe, so I’m not sure how that would avoid data issues if multiple threads are accessing it. https://stackoverflow.com/a/12098115/227313
However, regardless of what happens on iOS, the Kotlin Native state rules will enforce certain things. I can tell you for sure Stately’s collections were not designed with performance in mind, and will have a review and possibly a new implementation at some point in the next few months. However, they’ll work. There’s also a linked list if COW list isn’t what you’re looking for.
For performance, I’d probably have a list local to a thread and push/pull with a worker, but I have no idea what you’re trying to build.
q

Qinghua

11/03/2019, 8:29 AM
For this solution “For performance, I’d probably have a list local to a thread and push/pull with a worker”, does
worker
support sync pull mechanism like
dispatch_sync
?
Thanks for your detailed explanation. Actually, the performance is just my consideration in advance and we have not encountered concrete performance issue in our product now.
o

olonho

11/03/2019, 12:51 PM
also note, that https://github.com/JetBrains/kotlin-native/blob/master/runtime/src/main/kotlin/kotlin/native/concurrent/MutableData.kt can be used for mutable shared binary data.
View count: 2