Setting property "maxConcurrentOperationCount = 1" of NSOperation fails to execute operations using OpenSource Foundation.


(Mamatha Busi) #1

Hello

Code snippet:

···

———————————————————————

let operation1 : NSBlockOperation = NSBlockOperation (block: {

sleep(1)

print(“Opertion1”)

})

let operation2 : NSBlockOperation = NSBlockOperation (block: {

sleep(1)

print("Opertion2”)

})

var operations = NSOperation

operations.append(operation1)

operations.append(operation2)

let queue = NSOperationQueue()

queue.maxConcurrentOperationCount = 1

queue.addOperations(operations, waitUntilFinished: true)

————————————————————————

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.

The error I am seeing is:

fatal error: unexpectedly found nil while unwrapping an Optional value

Stack trace points to: attr = DISPATCH_QUEUE_SERIAL

which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue

The same test-case passes on OSx.

When I do not restrict the serial operation i.e. I remove ‘ queue.maxConcurrentOperationCount = 1’ , test case executes successfully.

Setting it to a different value other than 1 also causes no problems.

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?

Thank you.

Regards

Mamatha


(Philippe Hausler) #2

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.

···

On May 5, 2016, at 1:15 AM, Mamatha Busi via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hello

Code snippet:

———————————————————————

     let operation1 : NSBlockOperation = NSBlockOperation (block: {

            sleep(1)

            print("Opertion1")

        })

        let operation2 : NSBlockOperation = NSBlockOperation (block: {

            sleep(1)

            print("Opertion2”)

        })

        var operations = [NSOperation]()

        operations.append(operation1)

        operations.append(operation2)

        let queue = NSOperationQueue()

        queue.maxConcurrentOperationCount = 1

        queue.addOperations(operations, waitUntilFinished: true)

————————————————————————

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.

The error I am seeing is:

fatal error: unexpectedly found nil while unwrapping an Optional value

Stack trace points to: attr = DISPATCH_QUEUE_SERIAL

which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue

The same test-case passes on OSx.

When I do not restrict the serial operation i.e. I remove ‘ queue.maxConcurrentOperationCount = 1’ , test case executes successfully.

Setting it to a different value other than 1 also causes no problems.

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?

Thank you.

Regards
Mamatha

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Philippe Hausler) #3

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.

···

Sent from my iPhone

On May 6, 2016, at 12:16 AM, Mamatha Busi <mamabusi@in.ibm.com> wrote:

@ 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.

But this makes me think as to why until now, this was not caught by the compiler itself?

Regards
Mamatha

----- Original message -----
From: phausler@apple.com
To: Mamatha Busi/India/IBM@IBMIN
Cc: swift-corelibs-dev <swift-corelibs-dev@swift.org>
Subject: Re: [swift-corelibs-dev] Setting property "maxConcurrentOperationCount = 1" of NSOperation fails to execute operations using OpenSource Foundation.
Date: Thu, May 5, 2016 10:54 PM

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.

On May 5, 2016, at 1:15 AM, Mamatha Busi via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hello

Code snippet:

———————————————————————

     let operation1 : NSBlockOperation = NSBlockOperation (block: {

            sleep(1)

            print("Opertion1")

        })

        let operation2 : NSBlockOperation = NSBlockOperation (block: {

            sleep(1)

            print("Opertion2”)

        })

        var operations = [NSOperation]()

        operations.append(operation1)

        operations.append(operation2)

        let queue = NSOperationQueue()

        queue.maxConcurrentOperationCount = 1

        queue.addOperations(operations, waitUntilFinished: true)

————————————————————————

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.

The error I am seeing is:

fatal error: unexpectedly found nil while unwrapping an Optional value

Stack trace points to: attr = DISPATCH_QUEUE_SERIAL

which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue

The same test-case passes on OSx.

When I do not restrict the serial operation i.e. I remove ‘ queue.maxConcurrentOperationCount = 1’ , test case executes successfully.

Setting it to a different value other than 1 also causes no problems.

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?

Thank you.

Regards
Mamatha

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Mamatha Busi) #4

@ 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.

But this makes me think as to why until now, this was not caught by the compiler itself?

Regards

Mamatha

···

----- Original message -----
From: phausler@apple.com
To: Mamatha Busi/India/IBM@IBMIN
Cc: swift-corelibs-dev swift-corelibs-dev@swift.org
Subject: Re: [swift-corelibs-dev] Setting property “maxConcurrentOperationCount = 1” of NSOperation fails to execute operations using OpenSource Foundation.
Date: Thu, May 5, 2016 10:54 PM

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.

On May 5, 2016, at 1:15 AM, Mamatha Busi via swift-corelibs-dev swift-corelibs-dev@swift.org wrote:

Hello

Code snippet:

———————————————————————

let operation1 : NSBlockOperation = NSBlockOperation (block: {

sleep(1)

print(“Opertion1”)

})

let operation2 : NSBlockOperation = NSBlockOperation (block: {

sleep(1)

print("Opertion2”)

})

var operations = NSOperation

operations.append(operation1)

operations.append(operation2)

let queue = NSOperationQueue()

queue.maxConcurrentOperationCount = 1

queue.addOperations(operations, waitUntilFinished: true)

————————————————————————

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.

The error I am seeing is:

fatal error: unexpectedly found nil while unwrapping an Optional value

Stack trace points to: attr = DISPATCH_QUEUE_SERIAL

which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue

The same test-case passes on OSx.

When I do not restrict the serial operation i.e. I remove ‘ queue.maxConcurrentOperationCount = 1’ , test case executes successfully.

Setting it to a different value other than 1 also causes no problems.

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?

Thank you.

Regards

Mamatha


swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Dave Grove) #5

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.

--dave

            <swift-corelibs-dev@swift.org>

···

From: Philippe Hausler via swift-corelibs-dev
To: Mamatha Busi <mamabusi@in.ibm.com>
Cc: swift-corelibs-dev@swift.org
Date: 05/06/2016 09:43 AM
Subject: Re: [swift-corelibs-dev] Setting property
            "maxConcurrentOperationCount = 1" of NSOperation fails to
            execute operations using OpenSource Foundation.
Sent by: swift-corelibs-dev-bounces@swift.org

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.

Sent from my iPhone

On May 6, 2016, at 12:16 AM, Mamatha Busi <mamabusi@in.ibm.com> wrote:

      @ 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.

      But this makes me think as to why until now, this was not caught by
      the compiler itself?

      Regards
      Mamatha

       ----- Original message -----
       From: phausler@apple.com
       To: Mamatha Busi/India/IBM@IBMIN
       Cc: swift-corelibs-dev <swift-corelibs-dev@swift.org>
       Subject: Re: [swift-corelibs-dev] Setting property
       "maxConcurrentOperationCount = 1" of NSOperation fails to execute
       operations using OpenSource Foundation.
       Date: Thu, May 5, 2016 10:54 PM

       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.

             On May 5, 2016, at 1:15 AM, Mamatha Busi via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

             Hello

             Code snippet:

             ———————————————————————

                  let operation1 : NSBlockOperation = NSBlockOperation
             (block: {

                         sleep(1)

                         print("Opertion1")

                     })

                     let operation2 : NSBlockOperation = NSBlockOperation
             (block: {

                         sleep(1)

                         print("Opertion2”)

                     })

                     var operations = [NSOperation]()

                     operations.append(operation1)

                     operations.append(operation2)

                     let queue = NSOperationQueue()

                     queue.maxConcurrentOperationCount = 1

                     queue.addOperations(operations, waitUntilFinished:
             true)

             ————————————————————————

             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.

             The error I am seeing is:

             fatal error: unexpectedly found nil while unwrapping an
             Optional value

             Stack trace points to: attr = DISPATCH_QUEUE_SERIAL

             which implies that the libDispatch macro is coming as nil
             during the creation of the serial queue using libDispatch in
             the file NSOperationQueue

             The same test-case passes on OSx.

             When I do not restrict the serial operation i.e. I remove ‘
             queue.maxConcurrentOperationCount = 1’ , test case executes
             successfully.

             Setting it to a different value other than 1 also causes no
             problems.

             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?

             Thank you.

             Regards
             Mamatha

             _______________________________________________
             swift-corelibs-dev mailing list
             swift-corelibs-dev@swift.org
             https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

      _______________________________________________
      swift-corelibs-dev mailing list
      swift-corelibs-dev@swift.org
      https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Mamatha Busi) #6

Dave

I am running the test-case on Mac but with the OpenSource Foundation source code. Just FYI if you missed the earlier conversation.

-Mamatha

···

----- Original message -----
From: David P Grove/Watson/IBM
To: Philippe Hausler phausler@apple.com
Cc: Mamatha Busi mamabusi@in.ibm.com, swift-corelibs-dev@swift.org
Subject: Re: [swift-corelibs-dev] Setting property “maxConcurrentOperationCount = 1” of NSOperation fails to execute operations using OpenSource Foundation.
Date: Fri, May 6, 2016 8:12 PM

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.

–dave

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

From: Philippe Hausler via swift-corelibs-dev swift-corelibs-dev@swift.org
To: Mamatha Busi mamabusi@in.ibm.com
Cc: swift-corelibs-dev@swift.org
Date: 05/06/2016 09:43 AM
Subject: Re: [swift-corelibs-dev] Setting property “maxConcurrentOperationCount = 1” of NSOperation fails to execute operations using OpenSource Foundation.
Sent by: swift-corelibs-dev-bounces@swift.org


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.

Sent from my iPhone

On May 6, 2016, at 12:16 AM, Mamatha Busi mamabusi@in.ibm.com wrote:

      @ 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.
       
      But this makes me think as to why until now, this was not caught by the compiler itself?
       
      Regards
      Mamatha
  • ----- Original message -----
    From: phausler@apple.com
    To: Mamatha Busi/India/IBM@IBMIN
    Cc: swift-corelibs-dev swift-corelibs-dev@swift.org
    Subject: Re: [swift-corelibs-dev] Setting property “maxConcurrentOperationCount = 1” of NSOperation fails to execute operations using OpenSource Foundation.
    Date: Thu, May 5, 2016 10:54 PM

                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.
    
  ———————————————————————
       let operation1 : NSBlockOperation = NSBlockOperation (block: {
              sleep(1)
              print("Opertion1")
          })
          let operation2 : NSBlockOperation = NSBlockOperation (block: {
              sleep(1)
              print("Opertion2”)
          })
          var operations = [NSOperation]()
          operations.append(operation1)
          operations.append(operation2)
          let queue = NSOperationQueue()
          queue.maxConcurrentOperationCount = 1
          queue.addOperations(operations, waitUntilFinished: true)
  ————————————————————————
  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.
  The error I am seeing is:
  **fatal error: unexpectedly found nil while unwrapping an Optional value**
  **Stack trace points to:** attr = DISPATCH_QUEUE_SERIAL
  which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue
  The same test-case passes on OSx.
  When I do not restrict the serial operation i.e. I remove ‘  queue.maxConcurrentOperationCount = 1’ , test case executes successfully.
  Setting it to a different value other than 1 also causes no problems.
  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?
                          Thank you.
                           
                          Regards
                          Mamatha
                           
  
                          _______________________________________________
                          swift-corelibs-dev mailing list
                          swift-corelibs-dev@swift.org
                          [https://lists.swift.org/mailman/listinfo/swift-corelibs-dev](https://lists.swift.org/mailman/listinfo/swift-corelibs-dev)
      `_______________________________________________
      swift-corelibs-dev mailing list
      swift-corelibs-dev@swift.org`
      `[https://lists.swift.org/mailman/listinfo/swift-corelibs-dev](https://lists.swift.org/mailman/listinfo/swift-corelibs-dev)`