Jump to content

[SOLVED] Function does not return


photo

Recommended Posts

I have a long-running application. Because of a bug in the sleep() function https://developer.unigine.com/forum/topic/2638-accuracy-of-sleep-function/ I have replaced it with the function below.

 

The problem is that on some occaisions, sometimes after an 20 hours, sometimes after just a minute the function does not appear to return and the Unigine process locks up and must be killed.

 

Can anyone see anything wrong with this?

 

Edit: the code is called by a thread that is started from init(). The update() function is empty and all work is done in the thread.



void mysleep(float howlong) {


  float now = clock();
  float then = now + howlong;
  log.message("Sleep enter for [%f]\n",howlong);

  while(clock() <= then) {
    usleep(1);
    wait;
  }
  log.message("Sleep done\n");

}

Link to comment
Do you have a single script thread or multiple (where more than one could be executing mysleep) ? 

 

Is this on Windows? Does the problem still occur if you remove the usleep? 

 

Out of interest, why call usleep? By using "wait", the time between each iteration of your loop will be the inverse frame rate anyway..

Link to comment

> Do you have a single script thread or multiple (where more than one could be executing mysleep) ? 

 

No, just one thread executing.

 

>  Is this on Windows? Does the problem still occur if you remove the usleep? 
 
Yes, windows only and the problem still occurs without the usleep. In fact I tried it first without and added that in to mitigate the lockups.
 
> Out of interest, why call usleep? By using "wait", the time between each iteration of your loop will be the inverse frame rate anyway..

 

The real issue I'm trying to get to is that the sleep() function becomes wildly inaccurate after the engine has been running for more than about 10 hours. For example a sleep(0.1) call may take up to 3 minutes to execute. I am trying everything I can think of to work around the issue.

Link to comment

Hi,

 

I belive we can close this topic. Here the solution that working correctly:
 

void mysleep(float howlong) {
    float current[];
    current[get_thread()] = howlong;
   
    while(current[get_thread()] > 0.0f) {
        current[get_thread()] -= engine.game.getFTime();
        wait;

    }
}
  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...