<html><body><p>I think the intuition about the dispatch overlay being the problem on Linux is right on. We may have to hack around the problem on the Foundation side until an improved overlay is available to use.<br><br>--dave<br><br><br><img width="16" height="16" src="cid:1__=0ABBF538DFC3F0EB8f9e8a93df938690918c0AB@" border="0" alt="Inactive hide details for Philippe Hausler via swift-corelibs-dev ---05/06/2016 09:43:06 AM---I have a feeling this is associat"><font color="#424282">Philippe Hausler via swift-corelibs-dev ---05/06/2016 09:43:06 AM---I have a feeling this is associated with the changes for IUO types that recently landed. I am very w</font><br><br><font size="2" color="#5F5F5F">From: </font><font size="2">Philippe Hausler via swift-corelibs-dev <swift-corelibs-dev@swift.org></font><br><font size="2" color="#5F5F5F">To: </font><font size="2">Mamatha Busi <mamabusi@in.ibm.com></font><br><font size="2" color="#5F5F5F">Cc: </font><font size="2">swift-corelibs-dev@swift.org</font><br><font size="2" color="#5F5F5F">Date: </font><font size="2">05/06/2016 09:43 AM</font><br><font size="2" color="#5F5F5F">Subject: </font><font size="2">Re: [swift-corelibs-dev] Setting property "maxConcurrentOperationCount = 1" of NSOperation fails to execute operations using OpenSource Foundation.</font><br><font size="2" color="#5F5F5F">Sent by: </font><font size="2">swift-corelibs-dev-bounces@swift.org</font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br><br><font size="4">I have a feeling this is associated with the changes for IUO types that recently landed. I am very worried that this actually could happen on Darwin targets as well. Perhaps it is the swift overlay for dispatch that is correcting the failure on Darwin and the dispatch on Linux is missing that annotation. Worth looking into.<br><br>Sent from my iPhone</font><br><font size="4"><br>On May 6, 2016, at 12:16 AM, Mamatha Busi <</font><a href="mailto:mamabusi@in.ibm.com"><u><font size="4" color="#0000FF">mamabusi@in.ibm.com</font></u></a><font size="4">> wrote:<br></font><ul><ul><font face="Arial"> </font><br><font face="Arial">@ Philippe: Your right. Converting the 'attr' to an optional did do the job of creating a serial queue successfully. Thanks for that. I will create a PR for this.</font><br><font face="Arial"> </font><br><font face="Arial">But this makes me think as to why until now, this was not caught by the compiler itself?</font><br><font face="Arial"> </font><br><font face="Arial">Regards</font><br><font face="Arial">Mamatha</font><br><font face="Arial"> </font><br><font face="Arial">----- Original message -----<br>From: </font><a href="mailto:phausler@apple.com"><u><font color="#0000FF" face="Arial">phausler@apple.com</font></u></a><font face="Arial"><br>To: Mamatha Busi/India/IBM@IBMIN<br>Cc: swift-corelibs-dev <</font><a href="mailto:swift-corelibs-dev@swift.org"><u><font color="#0000FF" face="Arial">swift-corelibs-dev@swift.org</font></u></a><font face="Arial">><br>Subject: Re: [swift-corelibs-dev] Setting property "maxConcurrentOperationCount = 1" of NSOperation fails to execute operations using OpenSource Foundation.<br>Date: Thu, May 5, 2016 10:54 PM<br> </font><br><font face="Arial">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.</font><br><font face="Arial"> </font><ul><ul><font face="Arial">On May 5, 2016, at 1:15 AM, Mamatha Busi via swift-corelibs-dev <</font><a href="mailto:swift-corelibs-dev@swift.org" target="_blank"><u><font color="#0000FF" face="Arial">swift-corelibs-dev@swift.org</font></u></a><font face="Arial">> wrote:</font><br><font face="Arial"> </font><br><font face="Arial">Hello</font><br><font face="Arial"> </font><p><b><font face="Arial">Code snippet:</font></b><p><font face="Arial">———————————————————————</font><p><font face="Arial"> let operation1 : NSBlockOperation = NSBlockOperation (block: {</font><p><font face="Arial"> sleep(1)</font><p><font face="Arial"> print("Opertion1")</font><p><font face="Arial"> })</font><p><font face="Arial"> let operation2 : NSBlockOperation = NSBlockOperation (block: {</font><p><font face="Arial"> sleep(1)</font><p><font face="Arial"> print("Opertion2”)</font><p><font face="Arial"> })</font><p><font face="Arial"> </font><p><font face="Arial"> var operations = [NSOperation]()</font><p><font face="Arial"> operations.append(operation1)</font><p><font face="Arial"> operations.append(operation2)</font><p><font face="Arial"> </font><p><font face="Arial"> let queue = NSOperationQueue()</font><p><font face="Arial"> queue.maxConcurrentOperationCount = 1</font><p><font face="Arial"> queue.addOperations(operations, waitUntilFinished: true)</font><p><font face="Arial"> </font><p><font face="Arial">———————————————————————— </font><p><font face="Arial"> </font><p><font face="Arial">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. </font><p><font face="Arial">The error I am seeing is: </font><p><b><font face="Arial">fatal error: unexpectedly found nil while unwrapping an Optional value</font></b><p><b><font face="Arial">Stack trace points to: </font></b><font face="Arial">attr = DISPATCH_QUEUE_SERIAL </font><p><font face="Arial">which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue</font><p><font face="Arial">The same test-case passes on OSx. </font><p><font face="Arial">When I do not restrict the serial operation i.e. I remove ‘ queue.maxConcurrentOperationCount = 1’ , test case executes successfully. </font><p><font face="Arial">Setting it to a different value other than 1 also causes no problems. </font><p><font face="Arial">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?</font><p><font face="Arial"> </font><br><font face="Arial">Thank you.</font><br><font face="Arial"> </font><br><font face="Arial">Regards</font><br><font face="Arial">Mamatha</font><br><font face="Arial"> </font><br><font face="Arial"><br>_______________________________________________<br>swift-corelibs-dev mailing list</font><u><font color="#0000FF" face="Arial"><br></font></u><a href="mailto:swift-corelibs-dev@swift.org" target="_blank"><u><font color="#0000FF" face="Arial">swift-corelibs-dev@swift.org</font></u></a><u><font color="#0000FF" face="Arial"><br></font></u><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev"><u><font color="#0000FF" face="Arial">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</font></u></a></ul></ul><font face="Arial"> </font><br><tt>_______________________________________________<br>swift-corelibs-dev mailing list<br>swift-corelibs-dev@swift.org<br></tt><tt><a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a></tt><tt><br></tt><br><br></ul></ul><BR>
</body></html>