Hydra icon indicating copy to clipboard operation
Hydra copied to clipboard

Ubuntu compilation error

Open sage444 opened this issue 6 years ago • 3 comments

/home/user/Project/.build/checkouts/Hydra.git-8391472609009747209/Sources/Hydra/Promise+Await.swift:99:20: error: binary operator '!=' cannot be applied to two 'DispatchQueue' operands
                guard self.queue != DispatchQueue.main else {
                      ~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~

Swift version 5.0.1 (swift-5.0.1-RELEASE)
Target: x86_64-unknown-linux-gnu

Ubuntu 16.04.6 LTS

sage444 avatar Apr 30 '19 06:04 sage444

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 
```	

sage444 avatar Apr 30 '19 09:04 sage444

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

sage444 avatar Apr 30 '19 09:04 sage444

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.

sage444 avatar Apr 30 '19 11:04 sage444