I have a project where it would be beneficial to control and read GPIO pins in the background. For instance, one of my GPIO pins would be used to trigger an ultrasonic sensor and then another another used to read the response time from the sensor. I would like to do this in the back ground continuously while my script performs other tasks that may take too much time for the ultrasonic sensor readings to be accurate if it is in my main thread. In another application, I would like to count encoder pulses (relatively slow) while the main code performs other task. Variables would only be read by the main thread so that no two threads would be writing data to the same variable. Is this possible with the Rpi2 and would this be the preferred method if it is?