Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-11323] Calendar is not thread-safe #3984

Open
swift-ci opened this issue Aug 17, 2019 · 2 comments
Open

[SR-11323] Calendar is not thread-safe #3984

swift-ci opened this issue Aug 17, 2019 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-11323
Radar None
Original Reporter aulanov (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 2773525e087aef23e6a04ba1cce9607d

is duplicated by:

  • SR-14879 Calendar not thread-safe in swift-corelibs-foundation

Issue Description:

I'm getting unpredictable results when invoking Calendar.startOfDay() from parallel threads on the same Calendar object. This only happens on Linux. (I wasn't able to reproduce the problem on Darwin)

import Foundation
let cal = Calendar(identifier: .gregorian)
let queue = DispatchQueue(label: "test", attributes: .concurrent)
let date = Date()
let start = cal.startOfDay(for: date)
for _ in 0...10000 {
  queue.async {
    precondition(start == cal.startOfDay(for: date))
  }
}

$ swift run
Precondition failed: file /home/cal/Sources/cal/main.swift, line 8
$

@spevans
Copy link
Collaborator

spevans commented Aug 21, 2019

#2481

@swift-ci
Copy link
Contributor Author

Comment by Andrey Ulanov (JIRA)

If you look at CFCalendar source code (https://github.com/apple/swift-corelibs-foundation/blob/master/CoreFoundation/Locale.subproj/CFCalendar.c) you'll see other code that is not thread-safe since it uses calendar->_cal as a temporary storage. The PR above only fixes the CFCalendarGetTimeRangeOfUnit invocation. I can see that at least the following CFCalendar functions will have the same problem:

CFCalendarAddComponentsV()

CFCalendarGetComponentDifferenceV()

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants