Liberty BASIC Community Forum
« lbpro.exe using cpu time while not running? »

Welcome Guest. Please Login or Register.
Sep 19th, 2017, 1:58pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: lbpro.exe using cpu time while not running?  (Read 3290 times)
GaRPMorE
Senior Member
ImageImageImageImage


member is offline

Avatar

"Not everything that counts can be counted, and not everything that can be counted counts." - Albert Einstein


PM


Posts: 288
xx lbpro.exe using cpu time while not running?
« Thread started on: Nov 9th, 2013, 7:11pm »

Have had a couple of instances recently where "lbpro.exe" is using 50% or more of my cpu time, even though I have no lb application running. Killed it with Task Manager, but why should this occur?
User IP Logged

from the world according to GaRPMorE
Brandon Parker
Board Moderator

member is offline

Avatar




PM

Gender: Male
Posts: 1115
xx Re: lbpro.exe using cpu time while not running?
« Reply #1 on: Nov 9th, 2013, 10:56pm »

Have you used it recently?

You may be inadvertently leaving the process running by not turning a timer off or something during code execution. Just speculation though......

{:0)

Brandon
User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: lbpro.exe using cpu time while not running?
« Reply #2 on: Nov 10th, 2013, 04:20am »

This can happen, I often find I have four or five "hung" sessions. It happens because I code errors that crash Liberty. Some errors are caught at compile, some at runtime, a few simply make Liberty disappear, it hasn't, the window has closed and vanished of the desktop but the program is still running, or stalled in a loop. The reason it's 50% is because that's the max cycles that Windows ever assigns to a program.

Stopping the sessions with CtrlAltDel and then using taskmanager is easy to do, so too a reboot. If you leave your machine on 24/7 like me you should check occasionally. If you boot fresh every day you probably don't need to do anything.

Or code more carefully smiley
User IP Logged

RichardRussell
Guest
xx Re: lbpro.exe using cpu time while not running?
« Reply #3 on: Nov 10th, 2013, 09:14am »

on Nov 10th, 2013, 04:20am, Rod wrote:
The reason it's 50% is because that's the max cycles that Windows ever assigns to a program.

Huh? Windows will happily assign (nearly) 100% of the CPU cycles - good thing too; I'd be pretty unhappy for some speed-critical program to run at only half the speed it theoretically should!

If you find that the maximum CPU usage of a single thread (not program) is 50%, that either means you have a dual-core CPU, or it's using 100% of a hyperthreaded (HT) CPU and Task Manager is giving a misleading report.

Richard.
User IP Logged

JohnnyD
Guru
ImageImageImageImageImage


member is offline

Avatar

"If something should, then it doesn't, isn't, can't, hasn't or won't"


Homepage PM

Gender: Male
Posts: 759
xx Re: lbpro.exe using cpu time while not running?
« Reply #4 on: Nov 10th, 2013, 4:51pm »

Hi,

If you are using a wait loop, then CPU usage can be quite high:

[wait]
scan
goto[wait]

sort of thing.

If you use:
[wait]
scan
calldll #kernel32,"Sleep", 100 as ulong, r as void
goto[wait]

this will reduce the CPU usage to virtually zero.

Any use?

JohnnyD

User IP Logged

GaRPMorE
Senior Member
ImageImageImageImage


member is offline

Avatar

"Not everything that counts can be counted, and not everything that can be counted counts." - Albert Einstein


PM


Posts: 288
xx Re: lbpro.exe using cpu time while not running?
« Reply #5 on: Nov 10th, 2013, 7:15pm »

It does not seem "reproducible." I run the same LB programs daily, in the same manner. Only twice did they seem to "stick."
User IP Logged

from the world according to GaRPMorE
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: lbpro.exe using cpu time while not running?
« Reply #6 on: Nov 11th, 2013, 04:04am »

Create a .exe out of this and run the .exe. Now open the Task Manager and scroll down to find liberty.exe, you will find it under background processes not apps if you are on Win8.

Code:
nomainwin
while 1
wend
 


This simply shows what's happening, your program is closing all it's windows but not ENDing. Since you are not running the ide or the mainwin, closing the application window makes Liberty "disappear".

Now its either wrong program flow, closing windows and not adding an END statement, or you have a bug that is not being caught at runtime. But since the program is running and using CPU cycles my money is on wrong program flow.
User IP Logged

GaRPMorE
Senior Member
ImageImageImageImage


member is offline

Avatar

"Not everything that counts can be counted, and not everything that can be counted counts." - Albert Einstein


PM


Posts: 288
xx Re: lbpro.exe using cpu time while not running?
« Reply #7 on: Nov 11th, 2013, 8:14pm »

To reiterate: " I run the same LB programs daily, in the same manner. Only twice did they seem to "stick."
I also have a tokenized program that I use every day, that occasionally came up with a "runtime error" of "invalid branch label," although the branch was obviously present in the program. As they say, s__t happens. And when an OS is as complicated as Windows, it is bound to occur, sooner or later.




« Last Edit: Nov 11th, 2013, 8:15pm by GaRPMorE » User IP Logged

from the world according to GaRPMorE
Brandon Parker
Board Moderator

member is offline

Avatar




PM

Gender: Male
Posts: 1115
xx Re: lbpro.exe using cpu time while not running?
« Reply #8 on: Nov 12th, 2013, 12:06am »

on Nov 11th, 2013, 8:14pm, GaRPMorE wrote:
To reiterate: "I also have a tokenized program that I use every day, that occasionally came up with a "runtime error" of "invalid branch label," although the branch was obviously present in the program. As they say, s__t happens. And when an OS is as complicated as Windows, it is bound to occur, sooner or later.


Here is the first clue.....

This should not happen if everything is in order in your program. You should never be in a situation where a branch label can be called and it not be within the current scope of the program (ie. within a sub). This is one reason I will normally just use subroutines/ functions in my programs, but each person has his/ her own coding style and if you want to use the timer you have no choice but to use a branch label for it.

Are you using the Timer command in your program? You should turn the timer off after entering a lengthy subroutine/ function and then turn it back on just prior to exiting the function. This will prevent the timer from firing while the program is inside a subroutine/ function. This is pretty much the most common cause of spurious "invalid branch label" errors.

Where the branch label would be called from such things as buttons you can always disable them while other lengthy code is running and then enable them after it has completed.

I am sure if you can post some code that sometimes causes the problem we can help you figure it out and make the program work 100% of the time.


{:0)

Brandon
« Last Edit: Nov 12th, 2013, 12:08am by Brandon Parker » User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: lbpro.exe using cpu time while not running?
« Reply #9 on: Nov 12th, 2013, 02:16am »

I agree with Brandon, you definitely have a program flow coding error. If you mix subs and [branchlabel] coding structures it is very easy to trip up and find that you are trying to handle an event, button press, or timer event inside a sub that cannot see the [branchlabel]. Also it is quite unusual for a "hung" program to continue running and consume CPU cycles. You have definitely coded a never ending loop that is invoked after the windows are closed. Forgetting to issue a timer 0 statement on jumping to [quit] would typically close all the windows then the timer event would haul the program flow back to whatever timed loop is coded.

Can you zip the program and load it somewhere for us to down load?
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1681
xx Re: lbpro.exe using cpu time while not running?
« Reply #10 on: Nov 12th, 2013, 02:27am »

The problem is, sometimes event fires inside a sub that it shouldn't fire at all (like, no SCAN or WAIT - supposed to be no event?)
I experienced this, but it is hard to repeat sad
so I even don't have bug report.
User IP Logged

damned Dog in the Manger
RichardRussell
Guest
xx Re: lbpro.exe using cpu time while not running?
« Reply #11 on: Nov 12th, 2013, 03:56am »

on Nov 12th, 2013, 02:27am, tsh73 wrote:
The problem is, sometimes event fires inside a sub that it shouldn't fire at all (like, no SCAN or WAIT - supposed to be no event?)

Exactly. Events in LB are supposed to be synchronous: they should only fire when a SCAN or WAIT statement is executed. Therefore only when one of those statements is present within a SUB or FUNCTION should it be possible for the timer or a button-press event to result in a jump to an out-of-scope label.

Assuming the OP's program does not have a SCAN or WAIT in any of the subroutines or functions, the precautions advised by Brandon and Rod ought not to be necessary. If they are, it implies that the underlying issue is a bug in LB, as Anatoly hints at.

Richard.
User IP Logged

Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14485
xx Re: lbpro.exe using cpu time while not running?
« Reply #12 on: Nov 12th, 2013, 05:33am »

on Nov 12th, 2013, 03:56am, Richard Russell wrote:
Exactly. Events in LB are supposed to be synchronous: they should only fire when a SCAN or WAIT statement is executed. Therefore only when one of those statements is present within a SUB or FUNCTION should it be possible for the timer or a button-press event to result in a jump to an out-of-scope label.


Richard.


Richard, I truly appreciate your expertise in this area, however it has always been my understanding that SCAN and WAIT process user events. The timer fires at the prescribed interval (or queues if the system is busy).

For this reason, I believe Brandon is correct. A sub or function that takes longer to execute than the timer interval will cause an "invalid branch label" error, since the associated branch label is not visible in that scope.

Help:
Quote:
SCAN

The SCAN statement causes Liberty BASIC to stop what it is doing for a moment and process Windows keyboard and mouse messages.


Quote:
WAIT

This simple statement causes program execution to stop and wait for user input events. When the user interacts with a window or other control owned by the program and generates an event, program execution resumes at the event handler appropriate for their interaction.
User IP Logged

RichardRussell
Guest
xx Re: lbpro.exe using cpu time while not running?
« Reply #13 on: Nov 12th, 2013, 07:07am »

on Nov 12th, 2013, 05:33am, Alyce Watson wrote:
it has always been my understanding that SCAN and WAIT process user events. The timer fires at the prescribed interval (or queues if the system is busy).

I agree that the documentation is ambiguous, however it seems to me that there would be little point in making only 'user triggered' events (such as button presses) synchronous, whilst timer events are asynchronous. The value of having the SCAN statement would be greatly diminished.

It's not difficult to do the experiment. Try running this program firstly as listed, and then with the scan commented out:

Code:
timer 1000, [tick]
[idle]
scan
calldll #kernel32, "Sleep", 10 as long, r as long
goto [idle]

[tick]
print "Timer interrupt"
goto [idle] 

What I find here is that with the scan present the program prints 'Timer interrupt' once per second, as expected, but with the scan disabled it prints nothing. My interpretation is that, in normal circumstances, a timer interrupt - as with all other events - fires only in a SCAN or WAIT.

If it is indeed the case that a timer event can occur at other times, as has apparently been observed, this would appear to be an anomalous behaviour. This ties in with Anatoly's comment that "I experienced this, but it is hard to repeat".

Edit: Try this program as well. It spends nearly all its time in the SUB, so if your hypothesis was correct the [tick] label would be almost continuously out-of-scope and it would fail immediately - but it doesn't!

Code:
timer 1000, [tick]
[idle]
scan
call delay 50
goto [idle]

[tick]
print "Timer interrupt"
goto [idle]

sub delay howmany
for i = 1 to howmany
  calldll #kernel32, "Sleep", 1 as long, r as long
next
end sub 

Richard.
« Last Edit: Nov 12th, 2013, 08:23am by RichardRussell » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: lbpro.exe using cpu time while not running?
« Reply #14 on: Nov 12th, 2013, 11:04am »

I don't think there is anything mysterious going on I think it is a simple program flow error.

If you wait or scan in a Sub or Function or jump anywhere that does so you are going to hit the problem. I don't agree that there is a mystery bug, scan and wait are required but events can queue so the scan or wait you code may not be catching the event you expect.

Code:
timer 1000, [tick]
[idle]
scan
call delay 50
goto [idle]

[tick]
print "Timer interrupt"
goto [idle]

sub delay howmany
for i = 1 to howmany
    scan
  calldll #kernel32, "Sleep", 1 as long, r as long
next
end sub
 


Code:
timer 1000, [tick]
[idle]
scan
call delay 50
goto [idle]

[tick]
print "Timer interrupt"
goto [idle]

sub delay howmany
for i = 1 to howmany
    for n= 1 to 1000 * howmany
    next
next
end sub
 


The timer tick queue catches folks out, so too the enter key press down, release up events. Until we see the code and the events that are programmed its a guessing game.
« Last Edit: Nov 12th, 2013, 11:07am by Rod » User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls