开发者

Android Sync needed in writing files and

开发者 https://www.devze.com 2023-03-21 13:38 出处:网络
I have an android application that runs a thread thar reads the sensor values and writes them to a file after 500ms.The values of sensors(accelerometer) are declared as global and change inside the se

I have an android application that runs a thread thar reads the sensor values and writes them to a file after 500ms.The values of sensors(accelerometer) are declared as global and change inside the sensorChange() event.I do not have a lock on read and write operations.Should I have some kind of a synchronized mechanism or is i开发者_运维问答t fine as one event performs the reading and the other writing.

eg,For Accelerometer I have a global variable xA,yA,zA,which are written into file 4 times every second and are updated in sensorChangeEvent().


If you have 2 threads - one reads a variable and another writes to the same variable, then you have to synchronize the access

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号