I have different/multiple concurrent tasks that write to the same array of data while a webview's javascript reads the data. Looking at the log it appears that my app can lock up when data collision occurs. Does Tasker provide any functions like a critical section to protect/lock sections of code that could be contending for the same data? My thought is to create a DataLock task that locks/waits for critical sections of code to execute so that only one task updates the array at a time. See Below:
Task: DataLock (1065)
A1: Wait Until [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ] If [ %GXDataLock ~ false ]
A2: Variable Set [ Name:%GXDataLock To:true Do Maths:Off Append:Off ]
*Note: Collision Handling = "Run Both Together"
Task: DataUnLock (1066)
A1: Variable Set [ Name:%GXDataLock To:false Do Maths:Off Append:Off ]
Both DataLock and DataUnLock would need the priority set to the same level, i.e. 10.
Calling it would look something like this:
UpdateArrayTask1 - Background task
DataLock true
Do Something with the array
DataLock false
UpdateArrayTask2 - Foreground task (called from the webviews Javascript, i.e change the spelling of a name)
DataLock true
Do Something with the array
DataLock false
ReadArray - Webview task (gets data, refreshes screen if name spelling changed...)
DataLock true
Read the array
DataLock false
This way only one Task would be able to lock the code and update the data, the other task would wait its turn until the unlock is called. I really don't care which task executes first. I just don't want to abort any tasks because it could get confusing for the user. For example if the user changes an array element at the same time Tasker is updating the status of the same element - choosing which one to abort is messy.
Is there a better way?
Cindy
UpdateArrayTask1 - Background task
Array Push %Que,1,Delete|Data to update the array
I have different/multiple concurrent tasks that write to the same array of data while a webview's javascript reads the data. Looking at the log it appears that my app can lock up when data collision occurs.