<div dir="ltr"><div><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">Hi,</span></div><div><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br></span></div><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">I have this little project (<a href="http://mod-swift.org">mod-swift.org</a>) in which I embed Swift into Apache. I’m trying to understand the implications of hosting GCD Swift code inside an Apache process&amp;thread.</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">Though I guess those are pretty generic questions.</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">- 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)?</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">- 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?</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">- What would accessing DispatchQueue.main mean in such a context? Is this attaching a serial queue to the first thread invoking it?</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">What I essentially want is this:</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">let workerQueue =</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">  DispatchQueue(label:      “sync-&gt;async-&gt;sync&quot;,</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">                attributes: DispatchQueue.Attributes.concurrent)</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">func doSomethingAsyncAndWait(@esc cb: (@esc done:()-&gt;())-&gt;()) {</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">  var done = DispatchSemaphore(value: 0)</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">  workerQueue.async {</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">    cb() { done.signal() }</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">  }</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">  done.wait()</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">}</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">Is there anything I need to consider when doing this?</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px">Thanks a lot!</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px"> Helge</span><br style="color:rgb(0,0,0);font-family:monospace;font-size:14px"></div>