Open sage444 opened 5 years ago
I'm looking for solution in code and found that this check self.queue != DispatchQueue.main
is not relevant for the rest of function. Let me clarify
guard self.queue != DispatchQueue.main else { // there is check of self.queue and main
...
_ = semaphore.wait(timeout: .distantFuture) // call to semaphore.wait in outside context not self.queue
The root of this issue is that DispatchQueue
is not Equatable
on Linux. SO recommends using of setSpecific
/getSpecific
to tag queue and later distinguish but in my opinion for this particular case easiest solution is to use Thread.isMainThread
I ended up removing that check for main queue:). After that.
The worst case scenario is calling await
from some thread and providing the same thread as context that leads to little disaster:). AFAIK GCD's API does't provide functions for easy mitigation from this case. The correct solution requires additional queue for all calls from outside to ensure that we aren't locking sensitive threads, but it's more foolproofing in my opinion.
Calling semaphore.wait in main thread is not as bad as first case and I can imagine some practical reasons to do it.