sleep(ms) or delay(ms)

Hi,
In a point of my app, I need to stop the execution and wait for a sync event.

I can't find any sleep() or delay() function that stops some ms the execution without blocking the system.
The solution of programming a Timer and do a while(x){} is not valid for me. It would be if I could find a noop() function to put inside the "while", so the device doesn't freeze.

Do you know if there is a function for that?

Thank you!!!
  • Everything in ConnectIQ is supposed to be asynchronous.

    Normally, when programming under an asynchronous model like this, you'd pass a callback to be invoked when the work you want to wait for is complete. Whatever part of the application that is responsible for doing that work would invoke that callback when it is done, and then you'd do something in response to that.

    So you should never need to implement a no-op loop while waiting for something to happen. If you do implement a no-op loop, you're wasting cpu cycles and preventing other parts of the application from executing, which in many cases is a bad thing. Since there is only one thread of execution, the thing that you are waiting for is not likely to happen. You'd wait forever. There is a built-in watchdog that monitors calls to user code to ensure that they do not run too long. If you throw in a loop that waits, you're likely to run into problems because the watchdog bites you.

    If you need help trying to figure this all out, feel free to post some code and I'll try to help you out.

    Travis
  • Dear Travis,
    Thank you very much for your answer. I understand what you mean.

    The "problem" is that I'm doing calls to functions in some async events, that those calls are generating other events, etc. and I receive messages like this one:

    ERROR: Circular Dependency Error
    DETAILS: Unfreed memory on exit
    STORE_ID: 00000000000000000000000000000000
    CALLSTACK:

    I've identified where the "Circular dependency" could be, and I'm considering to program a Scheduler with a timer that checks if some events are triggered using a public variable, and doing the different calls from there.

    Also one other question: using Eclipse Neon, do you know how to view the program lines in the log files? Before, in case of error, I could see this line number, but not now ...

    Thank you again!
    Regards,

    Marc
  • The circular dependency error is just an indication that two objects somehow have references to each other. It is possible that you need to change your code to avoid a memory leak. One possible way to use a weak reference, but how you actually go about it depends heavily on your code.

    If you can, it may be good to send relevant snippets so we can pinpoint places where you can make changes to avoid the error.

    As for getting file and line numbers in the error messages, I don't really know why you wouldn't be seeing those when running under Neon.

    Travis
  • When you say you're not seeing the code and line numbers, is that when you run a sideload?

    Make sure that when you use the "Build for Device Wizard" you don't have "Build release Version of project" checked - that way you get the debug info in the .prg on your device. (the checkbox is at the bottom of the window, and you may have to scroll to see it)

    You'll get the line numbers when running in the sim, as that always uses a debug build.
  • Former Member
    Former Member over 8 years ago
    You won't ever see a line number associated with a Circular Dependency error, because the VM doesn't know where it was created. These are detected and logged only when the application shuts down. If there are allocations left in the poll after the application is terminated, a Circular Dependency is reported.