Hi, We are having some issues with threading / dispatch queues this week. Basically I’m wondering why the following “async” code has the output it does:
print(Thread.isMainThread) // true
DispatchQueue.main.async {
print(Thread.isMainThread) // false (???)
}
Whereas this same code but with “sync" prints “true” “true”:
print(Thread.isMainThread) // true
DispatchQueue.main.sync {
print(Thread.isMainThread) // true
}
This goes against what I thought I understood about Dispatch. Are there any
threading guarantees made by DispatchQueue at all? Especially on the main
queue. And if not, is there another construct we can use?
The issue is that we’re on Android (where the threading situation is cloudy at
best to begin with) and the JNI (Java-Native Interface) has specific
requirements about which threads its methods are run on. Let alone our graphics
rendering code.
Basically, initialising and using the JNI in separate DispatchQueue.main.async
blocks apparently does not end up on the same thread (and apparently neither of
them are the main thread). I’m quite confused by this.
Are there any resources or docs to get up to scratch with the internals of
Dispatch a bit better?
Thanks for your ears and eyes :)
– Geordie
signature.asc
Description: Message signed with OpenPGP
_______________________________________________ swift-corelibs-dev mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-corelibs-dev
