Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofThread consumes 100% CPU usage

$
0
0

@cuinjune wrote:

Hi, I'm trying to use ofThread but it is really expensive just for using the empty while loop in the threaded function.

Here's my code.

Everything in ofApp.h and nothing in ofApp.cpp

#pragma once

#include "ofMain.h"

class myThread : public ofThread {

public:

    myThread(){

        startThread();
    }
    ~myThread(){

        stopThread();
    }

private:

    void threadedFunction()
    {
        while (isThreadRunning()) {

        }
    }
};

class ofApp : public ofBaseApp{
	public:
		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y);
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);

    myThread thread;
};

When I run this code, the CPU is over 100%.
Is it normal? I'm using OF v0.9.8 on Mac OS X 10.11.6.
Any advise or guidance would be greatly appreciated!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles