Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Common Deadlock scenario

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Common Deadlock scenario

    I'm struggling to figure out a good way to handle this, as this is something that our product as well as any products which perform calculation from user interaction are affected by this. Long story short, I'd like to know what object NT 8 is syncing on internally so that we can serialize user interactions with the OnBarUpdate as well as user actions coming in on a separate (presumably the UI) thread.

    The issue is I need to lock off an object so that calculations aren't being affected while it's being updated. The problem is a race condition is easily created when we try to acquire our lock, while NT is trying to lock something else that another thread already has the lock to.

    What is the appropriate object to try to acquire a lock on to avoid this?

    See the screenshot here.


    To recreate the issue, simply use the sample indicator attached and either run it in Simulated Data or live marketdata and run for a couple minutes (use a fast chart, like a 2 second chart).

    Any insight would be greatly appreciated, thanks,

    Jeremy
    SharkIndicators
    Attached Files
    Jeremytang
    NinjaTrader Ecosystem Vendor - Shark Indicators

    #2
    Hello Jeremytang,

    Thank you for your post.

    I will follow up with you when I have some information.

    Comment


      #3
      Hello Jeremytang,

      Thank you for your patience.

      NinjaTrader utilizes locks in various scenarios. There are multiple lock objects depending on the operation.

      The deadlock is occurring due to the IsValidDataPoint function. This is calling an internal function which in itself locks the NinjaScriptBase.SyncUpdate. You could switch over to locking on SyncUpdate but you're outside of our supported NinjaScript at this point and should heavily test to make sure no negative side effects occur due to locking on NinjaTrader managed lock objects.

      Please let me know if you have any questions.
      Last edited by NinjaTrader_PatrickH; 01-16-2018, 06:47 AM.

      Comment


        #4
        Thanks!

        Testing seems to indicate this works perfectly, thanks for the extremely quick response.
        Jeremytang
        NinjaTrader Ecosystem Vendor - Shark Indicators

        Comment


          #5
          don't want to hijack the thread. but how did you pull the thread stats report?

          Originally posted by Jeremytang View Post
          Testing seems to indicate this works perfectly, thanks for the extremely quick response.

          Comment


            #6
            Hi Patrick, or to whom this may concern,

            It looks like we're running into a lot of deadlock and locking issues, and after a few weeks of banging my head against the wall I'm hoping you could provide some insight. In particular can you let me know which objects are being locked (be it protected or internal or private) in the following circumstances?

            1) On market tick data (my current best guess is the Instrument's MarketSyncUpdate)
            2) OnBarUpdate (is it SyncUpdate?) if so what other functions lock this of note?
            3) TriggerCustomEvent

            I believe proper documentation into which objects are being locked is the only way 3rd party dev's will be able to successfully make bug free products that interact with the UI.

            Thanks and keep up the great support!
            Jeremytang
            NinjaTrader Ecosystem Vendor - Shark Indicators

            Comment


              #7
              Hello Jeremytang,

              Thank you for your follow up on this item.

              I am looking into this further on my end.

              Comment


                #8
                Hello Jeremytang,

                Thank you for your patience.

                Can you detail what items you need the lock for as far as implementation?

                If you want to interact with the UI you would use the Dispatcher as seen in our documentation at the following link: https://ninjatrader.com/support/help...-threading.htm

                The multi-threading is already built into NinjaTrader 8. If you are using locks you would need to be doing your own multi-threading which in turn would be outside the scope of support we provide.

                I look forward to your response.

                Comment


                  #9
                  To Whom it may concern,

                  I'm still struggling with this, here is an example of a deadlock. I've captured a screen with the parallel stacks, and you can see that the TriggerCustomEvent call has caused a deadlock with another thread (when called on the UI thread - a fairly typical thing to do)



                  Note, I'm not locking anything in my code at this point, just relying on TriggerCustomEvent for locking purposes.
                  It'd be ideal if we can know what object is being locked, so I can at least test to see if it's acquired already, and if so yield to avoid a deadlock.
                  Jeremytang
                  NinjaTrader Ecosystem Vendor - Shark Indicators

                  Comment


                    #10
                    Hello Jeremytang,

                    I have attempted to reproduce the deadlock by calling TriggerCustomEvent on a UI thread and was unable to reproduce the deadlock. Could you attach a barebones example that we can test on our end and submit for further internal review?

                    Before we get into a feature request for a way to identify locks I would like to present this question alongside the test case so we can advise a best practice.

                    I look forward to your reply.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Jeremytang,

                      Could you confirm if you have received my message regarding a sample where I can encounter this behavior?

                      I look forward to your reply.
                      JimNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by junkone, Today, 11:37 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post junkone
                      by junkone
                       
                      Started by quantismo, 04-17-2024, 05:13 PM
                      5 responses
                      34 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by proptrade13, Today, 11:06 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by love2code2trade, 04-17-2024, 01:45 PM
                      4 responses
                      34 views
                      0 likes
                      Last Post love2code2trade  
                      Started by cls71, Today, 04:45 AM
                      2 responses
                      10 views
                      0 likes
                      Last Post eDanny
                      by eDanny
                       
                      Working...
                      X