Sketch Priority ?

edited February 2017 in How To...

Is there a way to give a sketch a higher priority ?

Answers

  • In what sense?

  • I'm running processing on a Raspberry Pi 2 with debian jessie which allows executables to have higher thread prioritys. Just wondering if it's possible to give a sketch a higher priority with my setup.

  • The code on this webpage should help.

  • The code seems to just create a separate thread but it does not change the sketch thread priority.

  • Answer ✓

    I am afraid your last statement is wrong, no new thread is being created and in a Processing sketch Thread.currentThread(); returns the Animation Thread.

    I created the sketch below from the code from my link.

    Use the + and - keys to change the Animation Thread priority between 1 and 10 inclusive, it starts at 5.

    void setup() {
      size(300, 300);
      fill(0);
    }
    
    void draw() {
      background(255);
      Thread t = Thread.currentThread();
      text(t.getName() + "  : priority = " + t.getPriority(), 20, 30);
    }
    
    void keyTyped() {
      if (key == '+' || key == '-') {
        int delta = (key == '+') ? 1 : -1;
        Thread t = Thread.currentThread();
        int priority = t.getPriority();
        int newPriority = constrain(priority + delta, 1, 10);
        if (newPriority != priority) 
          t.setPriority(newPriority);
      }
    }
    
  • edited November 2015

    Thank you for the information Sir. This does work.:)

Sign In or Register to comment.