Bug 427052 - The "wait" command cause cpu overheat
Summary: The "wait" command cause cpu overheat
Status: REPORTED
Alias: None
Product: kturtle
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Cies Breijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-28 00:15 UTC by hugues.larrive
Modified: 2020-10-21 01:04 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hugues.larrive 2020-09-28 00:15:23 UTC
SUMMARY
The "wait" command cause cpu overheat !

STEPS TO REPRODUCE
Running the following code :
reset
wait 10

OBSERVED RESULT
On an i7-8665U, CPU run at full speed (4.20GHz turbo boost) for 10 seconds

EXPECTED RESULT
CPU stay cool (~700MHz)

SOFTWARE/OS VERSIONS
kturtle 19.12.3 / Ubuntu 20.04 / Mate desktop
kturtle 18.04.1 / Debian buster / Mate desktop
kturtle 18.04.1 (backported) / Debian stretch amd64 / Mate desktop
kturtle 18.04.1 (backported) / Debian stretch i386 / Mate desktop
kturtle 16.08.3 / Debian stretch i386 / Mate desktop

ADDITIONAL INFORMATION
I have solved the problem for myself using the following workaround:
+++ kturtle-19.12.3/src/interpreter/executer.cpp
@@ -26,14 +26,13 @@
 #include <errno.h>
 #include <math.h>
 
-#include <QTimer>  // for wait
+#include <unistd.h> // for usleep
 #include <QDebug>
 
 #include <krandom.h>
 #include <KLocalizedString>
 #include <QtMath>
 
 void Executer::initialize(TreeNode* tree, ErrorList* _errorList)
 {
 	rootNode       = tree;
@@ -631,7 +630,9 @@ void Executer::executeWait(TreeNode* nod
 	if (!checkParameterQuantity(node, 1, 20000+Token::Wait*100+90)) return;
 	if (!checkParameterType(node, Value::Number, 20000+Token::Wait*100+91) ) return;
 	waiting = true;
-	QTimer::singleShot(static_cast<int>(1000*node->child(0)->value()->number()), this, &Executer::stopWaiting);
+	usleep(static_cast<int>(1000000*node->child(0)->value()->number()));
+	waiting = false;
+	return;
 }
 void Executer::executeAssert(TreeNode* node) {
 //	//qDebug() << "called";

so I don't know if it is a bug from kturtle or from QT, I don't really understanding c++...

Happy Hacking.
Comment 1 Christoph Feck 2020-10-21 01:04:25 UTC
The reason kturtle does not use usleep() is that this function prevents the application from handling display server input (e.g. for window refreshes).

Still, it shouldn't busy-wait until the timer fires.