Questions tagged [ios-multithreading]
59 questions
9
votes
1 answer
Atomic property wrapper only works when declared as class, not struct
I have created a "lock" in Swift and an Atomic property wrapper that uses that lock, for my Swift classes as Swift lacks ObjC's atomic property attribute.
When I run my tests with thread sanitizer enabled, It always captures a data race on a…

Yousef Hamza
- 347
- 1
- 3
- 13
8
votes
1 answer
is reference assignment atomic in Swift 5?
Do I need some kind of explicit synchronization in this case?
class A {
let val: Int;
init(_ newVal: Int) {
val = newVal
}
}
public class B {
var a: A? = nil
public func setA() { a = A(0) }
public func hasA() -> Bool { return a…

Alex Cohn
- 56,089
- 9
- 113
- 307
8
votes
2 answers
Does sync/async behave similar to serial/concurrent i.e., do they both control DispatchQueues or do sync/Async control Threads only
Most answers on stackoverflow implies in a way that sync vs async behaviour is quite similar to serial vs concurrent queue concept difference. Like the link in the first comment by @Roope
I have started to think that
Serial and concurrent are…

Aron
- 91
- 5
7
votes
1 answer
Multithreaded rendering only crashes on iOS 13
In my game engine, I have an option to enable the multithreaded rendering.
In iOS 12 (and below) my app did not crash.
I have not changed anything in my code, but it crashes on iOS 13.
2019-10-02 11:36:07.931 SimpleGame[293:11150] ---> (Inner…

신한슬
- 189
- 12
6
votes
1 answer
Why do we need to call the Main Thread for UI updates?
I know that we have to call the main thread when we update the UI.
But I can't explain my teammates why we have to do it and why Swift doesn't do it automatically.
They used to call self.present() like this:
self.present(alert, animated:…

Godlike
- 1,621
- 2
- 20
- 33
5
votes
1 answer
Xcode Incorrectly Reporting Swift Access Race Condition
I believe XCode is incorrectly reporting Swift Access Race in my SynchronizedDictionary - or is it?
My SynchronizedDictionary looks like this:
public struct SynchronizedDictionary {
private var dictionary = [K: V]()
private…

Pelle Stenild Coltau
- 1,268
- 10
- 15
3
votes
1 answer
How to cancel the delayed thread?
I am executing set of tasks, and in order to span them over time I've used Thread.sleep(forTimeInterval: ... ) It adds pauses between executions.
Then, on the main screen I have controllers, that can intervene into thread execution, so when…

MikeMaus
- 385
- 3
- 22
3
votes
1 answer
Is it possible to execute something on main thread after didEnterBackground is called?
First of all I'd like to say sorry in case you consider my question dummy, I'm new to iOS and multithreading and just want to understand how things are going on. As far as I know didEnterBackground is the last function that iOS calls before app…

starwarrior8809
- 361
- 1
- 10
3
votes
1 answer
Playing instance of AVAudioPlayer from background thread sometimes fails
I am trying to play a sound from a background thread using an instance of an AVAudioPlayer in Swift 5. Most of the time, it will be successful. But once in a while the audio player fails to play a sound.
It appears as though calling play() twice, or…

star8163264
- 148
- 2
- 8
3
votes
3 answers
How to take a screenshot of UIView on a background thread?
The app I'm working on has google maps on almost every screen. To save memory, I'm reusing the same google maps view everywhere. The problem is, when you pop a viewController, you can see a white space where the map was. To work around that I'm…

Senõr Ganso
- 1,694
- 16
- 23
3
votes
1 answer
Copy-on-Write in Multi-threaded environment in Swift
I've read about Copy-on-Write concept for optimization in Arrays and other data structures in Swift.
What I want to know is how Copy-on-Write works in a multi-threaded environment.
let arr1 = [1, 2, 3, 4]
let arr2 = arr1
…

PGDev
- 23,751
- 6
- 34
- 88
3
votes
1 answer
How to send tasks to the background queue in Swift?
I have a local notification that is set when a user taps a button. I want to send this to the background thread and then update the UI. Is this a safe way to do it?
DispatchQueue.global(qos: .background).async { // sends registration to…

ayjoy
- 155
- 3
- 10
2
votes
1 answer
How does .enforceQoS flag increase priority?
I tried to increase the priority of the block executed in the concurrent queue. I suggested that the flag enforceQoS is suitable for this purpose. As Apple docs said:
This flag prioritizes the block's quality-of-service class over the one…

V.V.V
- 235
- 1
- 13
2
votes
1 answer
Does didFinishPickingMediaWithInfo get called in background thread?
I thought that the UIImagePickerController delegate methods (or any UIKit delegate method) get called in the main thread. But here, when picking image from gallery or camera, the didFinishPickingMediaWithInfo method does not seem to get called in…

badhanganesh
- 3,427
- 3
- 18
- 39
2
votes
1 answer
Realm - Batch update RLMResults on background thread
I have RLMResults that I need to iterate over, do a potentially "long-running" download task, (long enough it shouldn't be on the main thread), and update each object with the result of this download. The latest iteration on what I've attempted…

Mike
- 9,765
- 5
- 34
- 59