[swift-users] GCD interaction w/ external threads

Helge Hess helge.hess at googlemail.com
Thu Apr 6 06:10:08 CDT 2017


Hi,

I have this little project (mod-swift.org) in which I embed Swift into
Apache. I’m trying to understand the implications of hosting GCD Swift code
inside an Apache process&thread.
Though I guess those are pretty generic questions.

- Can I create a concurrent queue from within an external thread and
dispatch blocks to that (and then use a barrier or semaphore to wait on
completion)?

- Is the external thread in any way touched by GCD? Would it somehow
automatically create a serial queue for it? Or reuse the thread for queues
created from it?

- What would accessing DispatchQueue.main mean in such a context? Is this
attaching a serial queue to the first thread invoking it?

What I essentially want is this:

let workerQueue =
  DispatchQueue(label:      “sync->async->sync",
                attributes: DispatchQueue.Attributes.concurrent)

func doSomethingAsyncAndWait(@esc cb: (@esc done:()->())->()) {
  var done = DispatchSemaphore(value: 0)
  workerQueue.async {
    cb() { done.signal() }
  }
  done.wait()
}

Is there anything I need to consider when doing this?

Thanks a lot!
 Helge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170406/bbd220ea/attachment.html>


More information about the swift-users mailing list