Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause, resume #14

Closed
mhtvsSFrpHdE opened this issue Aug 6, 2022 · 2 comments
Closed

Pause, resume #14

mhtvsSFrpHdE opened this issue Aug 6, 2022 · 2 comments

Comments

@mhtvsSFrpHdE
Copy link
Owner

mhtvsSFrpHdE commented Aug 6, 2022

True perfect pause not exist

By learn video and document, seems there were no something called "perfect pause at any time".
The implement is use cross thread variable, and tons of if statement to check the variable is changed or not.

Flavor

I personally don't like to see I do one thing a time, but do 150 times to check on a variable.

What is my pause

When I say a pause, I went to gaming or performance matter task.
After I return, I probably don't want to resume from where I left.
Only god know what's in the RAM now. I will continue to prefetch from the start point.

The only case I pause is I don't want to rescan, keep scan result in RAM.
Or I just simply close the program, later start again is also a solution.

Utilize skip variable

So the solution should be done on thread entry, I remember there is a "skip" variable.
That's a chance. The variable has an initial value on creating a thread instance.
I will get the initial value from global, instead always use "false".

Once I set global variable to "true", all new created read thread will inherit "true".
When they are fired, will return immediately and do nothing.

What to do thread runner

The thread pool runner will fire all the thread anyway.
It will change to only check global pause status once before fire any thread.
If thread pool already running, for example 47/1055,
all 1055 thread will fire, and counting on "skip" variable.

The reason mentioned before, I don't like to see every time I do something,
but first I checked a suddenly appeared variable.

Resume

I have PrefetchInterval, the one currently is use sleep on loop thread.
After send resume command, the rest of interval time should discard and do prefetch now.
So instead of sleep on the loop thread, the sleep will change to a new thread,
and loop thread will try to join the sleep thread.

In this case, when it comes to resume, I terminate the sleep thread,
prefetch will start immediately.

@mhtvsSFrpHdE
Copy link
Owner Author

mhtvsSFrpHdE commented Aug 6, 2022

Therefore, I have the following task:

  • Create pause status variable at a handy place b5ebb2b
  • Use pause variable as skip variable initial value 7e812ec
  • Move PrefetchInterval sleep statement to new thread 3b6331f
  • Save the thread address to a handy place, so can destroy at any time 8a4690d
  • Join the thread on loop thread after sleep thread is fired 3b6331f
  • A command interface thread 1a1c9eb
  • Before consume thread pool, check pause variable status
    if true, keep waiting for next interval 5a89be9
  • In pause function, set skip to true adf85e4
  • In resume function, set skip to false and terminate sleep thread ef37a6d

@mhtvsSFrpHdE
Copy link
Owner Author

mhtvsSFrpHdE commented Aug 7, 2022

Command interface

  • Basically is a while loop
  • Run thread different from read loop
  • cin, std string, cout QString, QTextStream(stdin)

@mhtvsSFrpHdE mhtvsSFrpHdE changed the title Pause, resume, stop code Pause, resume Aug 7, 2022
@mhtvsSFrpHdE mhtvsSFrpHdE mentioned this issue Aug 7, 2022
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant