Post

Replies

Boosts

Views

Activity

GCD TSAN issue: Data race in generic specialization <Foundation.UUID>
The XCODE TSAN thread analyser is throwing up a threading issue: Data race in generic specialization <Foundation.UUID> of Swift._NativeSet.insertNew(_: __owned τ_0_0, at: Swift._HashTable.Bucket, isUnique: Swift.Bool) -> () at 0x10a16b300 This only occurs in a release build, and its Data race in generic specialization that has my attention. It pin-points the addID function. But I cannot see the issue. Here is the relevant code snippet: final class IDBox { let syncQueue = DispatchQueue(label: "IDBox\(UUID().uuidString)", attributes: .concurrent) private var _box: Set<UUID> init() { self._box = [] } var box: Set<UUID> { syncQueue.sync { self._box } } func addID(_ id: UUID) { syncQueue.async(flags: .barrier) { self._box.insert(id) } } }
0
0
771
May ’22
SwiftUI app outputting CVDisplayLink related messages to console?
I'm getting a lot of output on the console as I run a MacOS based SwiftUI app I'm developing, for example: 2021-12-08 12:40:14.439565+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830820] CVCGDisplayLink::setCurrentDisplay: 1892262333 2021-12-08 12:40:14.439785+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830800] CVDisplayLinkCreateWithCGDisplays count: 1 [displayID[0]: 0x70c9a1bd] [CVCGDisplayLink: 0x7fe6e7830820] 2021-12-08 12:40:14.439827+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830800] CVDisplayLinkStart 2021-12-08 12:40:14.439853+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830820] CVDisplayLink::start 2021-12-08 12:40:14.439993+0000 SpDriveApp[6801:182706] [] [0x60000f698460] CVXTime::reset Has anyone else seen this? Have I accidentally switched on a diagnostic tool, or is there something else I am doing wrong?
11
0
4k
Apr ’22
NSFilePresenter update not firing on iPad - does on Mac with identical code.
I am writing an App with both Mac and iPad versions that saves its state to a file. The user can store the file in their iCloud and open it both on the Mac and iPad simultaneously. If an update is made on either device the other will update their state to match. This has been achieved using an NSFilePresenter / NSFileCoordinator approach. Both platforms are using identical code. At present when I make a change on the iPad, a few moments later the Mac updates as expected. However, this does not happen the other way around. If I update the data on the Mac the iPad never appears to receive an update. I've tried this on the simulator also. I get similar behaviour, but can get the iPad to update it I use the simulator's Sync With iCloud function. Any ideas of what I may be doing wrong - as clearly the code works in one direction!
1
0
1.7k
Mar ’22
Running FileManager.default.enumerator on different tasks
I'm writing a function where a directory and its descendants are scanned to produce a list of files. The function is part of a class, FileScanner. Here's a simplified version of the function: func scanFolder(_ folderURL: URL) async { // Set up configuration for directory search, varies based on need to search sub directories let resourceKeysArray: [URLResourceKey] = [.nameKey, .isDirectoryKey, .fileResourceTypeKey, .creationDateKey, .contentModificationDateKey, .contentTypeKey] let resourceKeysSet = Set&lt;URLResourceKey&gt;(resourceKeysArray) let options = FileManager.DirectoryEnumerationOptions(arrayLiteral: [.skipsHiddenFiles, .skipsPackageDescendants]) if let enumerator = FileManager.default.enumerator(at: folderURL, includingPropertiesForKeys: resourceKeysArray, options: options) { await folderScanStatus.markRunning() while await !folderScanStatus.cancelled, let fileURL = enumerator.nextObject() as? URL { print("\(id) found \(fileURL.path)") // Logging for debug purposes foundFiles.append(fileURL) } } } The code is async, as it has to call some async functions (I've left a couple in for illustration.) The user can have multiple scans in process simultaneously. For each one a new FileScanner is created, and de-inited once the scan has completed - the results are copied across elsewhere. scanFolder is called from within a Task: Task { await scanFolder(someURL) } I am finding that if two of these processes run at once, they can actually interfere with each other - i.e. one can scan the directory of the other. I added some logging to highlight the issue. The log line shows the ID of the scanner, and the file it has found. In this run there were two scanners: EDF43558-608E-47A4-81E5-97B9707B1D0F, scanning /Volumes/Back-up A/ 982EC712-D79E-4785-A1BA-3B53F85967F0, scanning /Users/TEST/ And here's some extracts from the log showing them working as expected: 982EC712-D79E-4785-A1BA-3B53F85967F0 found /Users/TEST/Files/R_24_04-04.txt EDF43558-608E-47A4-81E5-97B9707B1D0F found /Volumes/Back-up A/180704f01.txt And here's an example showing Scanner 982EC712-D79E-4785-A1BA-3B53F85967F0 finding a file that the other one also picked up: 982EC712-D79E-4785-A1BA-3B53F85967F0 found /Volumes/Back-up A/19839f92.txt : EDF43558-608E-47A4-81E5-97B9707B1D0F found /Volumes/Back-up A/19839f92.txt Any ideas why this is happening? I was under the impression FileManager was thread safe?
3
0
2.3k
Nov ’21
GCD TSAN issue: Data race in generic specialization <Foundation.UUID>
The XCODE TSAN thread analyser is throwing up a threading issue: Data race in generic specialization <Foundation.UUID> of Swift._NativeSet.insertNew(_: __owned τ_0_0, at: Swift._HashTable.Bucket, isUnique: Swift.Bool) -> () at 0x10a16b300 This only occurs in a release build, and its Data race in generic specialization that has my attention. It pin-points the addID function. But I cannot see the issue. Here is the relevant code snippet: final class IDBox { let syncQueue = DispatchQueue(label: "IDBox\(UUID().uuidString)", attributes: .concurrent) private var _box: Set<UUID> init() { self._box = [] } var box: Set<UUID> { syncQueue.sync { self._box } } func addID(_ id: UUID) { syncQueue.async(flags: .barrier) { self._box.insert(id) } } }
Replies
0
Boosts
0
Views
771
Activity
May ’22
SwiftUI app outputting CVDisplayLink related messages to console?
I'm getting a lot of output on the console as I run a MacOS based SwiftUI app I'm developing, for example: 2021-12-08 12:40:14.439565+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830820] CVCGDisplayLink::setCurrentDisplay: 1892262333 2021-12-08 12:40:14.439785+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830800] CVDisplayLinkCreateWithCGDisplays count: 1 [displayID[0]: 0x70c9a1bd] [CVCGDisplayLink: 0x7fe6e7830820] 2021-12-08 12:40:14.439827+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830800] CVDisplayLinkStart 2021-12-08 12:40:14.439853+0000 SpDriveApp[6801:159299] [] [0x7fe6e7830820] CVDisplayLink::start 2021-12-08 12:40:14.439993+0000 SpDriveApp[6801:182706] [] [0x60000f698460] CVXTime::reset Has anyone else seen this? Have I accidentally switched on a diagnostic tool, or is there something else I am doing wrong?
Replies
11
Boosts
0
Views
4k
Activity
Apr ’22
NSFilePresenter update not firing on iPad - does on Mac with identical code.
I am writing an App with both Mac and iPad versions that saves its state to a file. The user can store the file in their iCloud and open it both on the Mac and iPad simultaneously. If an update is made on either device the other will update their state to match. This has been achieved using an NSFilePresenter / NSFileCoordinator approach. Both platforms are using identical code. At present when I make a change on the iPad, a few moments later the Mac updates as expected. However, this does not happen the other way around. If I update the data on the Mac the iPad never appears to receive an update. I've tried this on the simulator also. I get similar behaviour, but can get the iPad to update it I use the simulator's Sync With iCloud function. Any ideas of what I may be doing wrong - as clearly the code works in one direction!
Replies
1
Boosts
0
Views
1.7k
Activity
Mar ’22
Running FileManager.default.enumerator on different tasks
I'm writing a function where a directory and its descendants are scanned to produce a list of files. The function is part of a class, FileScanner. Here's a simplified version of the function: func scanFolder(_ folderURL: URL) async { // Set up configuration for directory search, varies based on need to search sub directories let resourceKeysArray: [URLResourceKey] = [.nameKey, .isDirectoryKey, .fileResourceTypeKey, .creationDateKey, .contentModificationDateKey, .contentTypeKey] let resourceKeysSet = Set&lt;URLResourceKey&gt;(resourceKeysArray) let options = FileManager.DirectoryEnumerationOptions(arrayLiteral: [.skipsHiddenFiles, .skipsPackageDescendants]) if let enumerator = FileManager.default.enumerator(at: folderURL, includingPropertiesForKeys: resourceKeysArray, options: options) { await folderScanStatus.markRunning() while await !folderScanStatus.cancelled, let fileURL = enumerator.nextObject() as? URL { print("\(id) found \(fileURL.path)") // Logging for debug purposes foundFiles.append(fileURL) } } } The code is async, as it has to call some async functions (I've left a couple in for illustration.) The user can have multiple scans in process simultaneously. For each one a new FileScanner is created, and de-inited once the scan has completed - the results are copied across elsewhere. scanFolder is called from within a Task: Task { await scanFolder(someURL) } I am finding that if two of these processes run at once, they can actually interfere with each other - i.e. one can scan the directory of the other. I added some logging to highlight the issue. The log line shows the ID of the scanner, and the file it has found. In this run there were two scanners: EDF43558-608E-47A4-81E5-97B9707B1D0F, scanning /Volumes/Back-up A/ 982EC712-D79E-4785-A1BA-3B53F85967F0, scanning /Users/TEST/ And here's some extracts from the log showing them working as expected: 982EC712-D79E-4785-A1BA-3B53F85967F0 found /Users/TEST/Files/R_24_04-04.txt EDF43558-608E-47A4-81E5-97B9707B1D0F found /Volumes/Back-up A/180704f01.txt And here's an example showing Scanner 982EC712-D79E-4785-A1BA-3B53F85967F0 finding a file that the other one also picked up: 982EC712-D79E-4785-A1BA-3B53F85967F0 found /Volumes/Back-up A/19839f92.txt : EDF43558-608E-47A4-81E5-97B9707B1D0F found /Volumes/Back-up A/19839f92.txt Any ideas why this is happening? I was under the impression FileManager was thread safe?
Replies
3
Boosts
0
Views
2.3k
Activity
Nov ’21