Fixed reading variable.

The variable needs to be read/written in "thread-safe" manner, else some hidden bugs might occur.