Results 1 to 5 of 5

Thread: Problem about timer in multithread programs

  1. #1
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Problem about timer in multithread programs

    Because the forum is not support the space charactor -> so i replace it with *

    ****obj*******obj***
    A ----------> B ----------> C
    ****Bus*******Car***

    In this model, Bus & Car is thread objects. Bus will move obj from A to B in 10 seconds. After that, Car will move obj from B to C in 10 seconds. The contraint is that Bus must finish before Car starts.

    To make a look-feel as Bus is running, I divide AB to 10 small distances, & I set interval for steps is 1 second because 10 steps * 1 second = 10 seconds -> this is the time duration for Bus finish AB. But when I use this way, in fact Bus will finish more 10 seconds, because we must plus the time for calculations in one step. So, we have:
    The time duration to finish AB = (1 + time_for_one_step)*10

    Although time_for_one_step is very small but If I divide AB smaller, the extra time is bigger.
    My problem is that how to Bus allways finish AB before 10 seconds but not too early.

    Thanks. Please help me.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem about timer in multithread programs

    Why don't you synchronize the threads, Bus and Car? Don't let Car start until Bus has finished? You can either use wait conditions or a global volatile flag or you could connect Bus's finished() signal to Car's start() slot - but this only if you are using Qt.

  3. #3
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem about timer in multithread programs

    Quote Originally Posted by marcel View Post
    Why don't you synchronize the threads, Bus and Car? Don't let Car start until Bus has finished? You can either use wait conditions or a global volatile flag or you could connect Bus's finished() signal to Car's start() slot - but this only if you are using Qt.
    My purpose is that how to run Bus in 10 seconds. Because my program is 3D simulation, it requires all objects must finish on time. If Bus doesn't finish in 10 seconds, Car will have to wait the Bus until it finish -> Car will be late. And if the model have some threads (as Truck move obj from C to D, ....), it will make the back threads run later.

    Really, with your solution, Bus will not move to B after 10 seconds -> Car will not move to C after 20 seconds (plus 10 seconds of Car).

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem about timer in multithread programs

    You can't do it in exactly 10 seconds. Apart from your considerations you also have to take into account the process scheduler, context switches and the time other processes are running on your "10" seconds.

    This is pretty difficult to achieve and you couldn't do it even on multiple core processors.
    Maybe on a real-time OS you could find the support to do it.

    But, with the common, desktop OS's , something AROUND 10 seconds should be enough.
    So, if you are confident that additional computations don't take more than 1 sec at each step, then in an asymptotic analysis they could be ignored.

    Otherwise you can do an analysis of you algorithm and derive the average time it takes to run.

  5. #5
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem about timer in multithread programs

    Quote Originally Posted by marcel View Post
    You can't do it in exactly 10 seconds. Apart from your considerations you also have to take into account the process scheduler, context switches and the time other processes are running on your "10" seconds.

    This is pretty difficult to achieve and you couldn't do it even on multiple core processors.
    Maybe on a real-time OS you could find the support to do it.

    But, with the common, desktop OS's , something AROUND 10 seconds should be enough.
    So, if you are confident that additional computations don't take more than 1 sec at each step, then in an asymptotic analysis they could be ignored.

    Otherwise you can do an analysis of you algorithm and derive the average time it takes to run.
    Thank you. How can I finish it in 10 seconds but not too early? Please give me your solution.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.