<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hmm that seems unfortunate. I wonder if the serial creation is due to an unwrapped optional? var attr: dispatch_queue_attr_t? instead might do the trick… or alternatively we could just let the underlying queue be concurrent all the time and enforce the max ops via making the semaphore always instantiated (in the case of max ops being 1) and initializing it to 1 to gate the operations.</div><br class=""><div><blockquote type="cite" class=""><div class="">On May 5, 2016, at 1:15 AM, Mamatha Busi via swift-corelibs-dev <<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt"><div dir="ltr" style="font-family:Arial;font-size:10.5pt" class=""><div dir="ltr" class="">Hello</div>
<div dir="ltr" class=""> </div>
<div dir="ltr" class=""><p class=""><b class="">Code snippet:</b></p><p class="">———————————————————————</p><p class=""> let operation1 : NSBlockOperation = NSBlockOperation (block: {</p><p class=""> sleep(1)</p><p class=""> print("Opertion1")</p><p class=""> })</p><p class=""> let operation2 : NSBlockOperation = NSBlockOperation (block: {</p><p class=""> sleep(1)</p><p class=""> print("Opertion2”)</p><p class=""> })</p><div class=""> <br class="webkit-block-placeholder"></div><p class=""> var operations = [NSOperation]()</p><p class=""> operations.append(operation1)</p><p class=""> operations.append(operation2)</p><div class=""> <br class="webkit-block-placeholder"></div><p class=""> let queue = NSOperationQueue()</p><p class=""> queue.maxConcurrentOperationCount = 1</p><p class=""> queue.addOperations(operations, waitUntilFinished: true)</p><div class=""> <br class="webkit-block-placeholder"></div><p class="">———————————————————————— </p><div class=""> <br class="webkit-block-placeholder"></div><p class="">The above code snippet of adding operations to an operation queue and executing with the property ‘maxConcurrentOperationCount = 1’ fails while executing the above with the OpenSource Foundation and libDispatch of MAC inside Xcode. </p><p class="">The error I am seeing is: </p><p class=""><b class="">fatal error: unexpectedly found nil while unwrapping an Optional value</b></p><p class=""><b class="">Stack trace points to: </b>attr = DISPATCH_QUEUE_SERIAL </p><p class="">which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue</p><p class="">The same test-case passes on OSx. </p><p class="">When I do not restrict the serial operation i.e. I remove ‘ queue.maxConcurrentOperationCount = 1’ , test case executes successfully. </p><p class="">Setting it to a different value other than 1 also causes no problems. </p><p class="">Am I doing something wrong with the API. If I set the property ‘ queue.maxConcurrentOperationCount = 1’ after adding operations to the queue, then the problem does not occur. But then this restricts me to control the operation execution to be serial. So, I expect the above snippet to work on OpenSource as well. Any thoughts on this?</p>
<div class=""> </div>
<div class="">Thank you.</div>
<div class=""> </div>
<div class="">Regards</div>
<div class="">Mamatha</div><div class=""> <br class="webkit-block-placeholder"></div></div></div></div><br class="">
_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev<br class=""></div></blockquote></div><br class=""></body></html>