Hi all, please consider the following:
I have a queue of objects represented as an array.
I process them off the top of the array (at position 1) before calling
arrayDeleteAt()
to remove it from the array.I add new queue item at the top of the array using
arrayAppend()
.
This works fine. However, I now wish to re-order the array immediately after adding an item.
I am concerned that if a thread is taking from the queue it will find the queue order has changed between it taking the item at position 1 and it deleting the item at position 1 - because in that time an additional item has been added the the queue has been re-sorted. So I need to ensure my queue is thread-safe.
Is there any way to doing this using the cflock
tag? Since my add and remove code are in different places in the code the thread executing one bit of code would need to know that a thread is executing another specific bit of code and halt until that other thread has stopped executing it's code.
Or am I better off just raising a flag while the sorting is going on and preventing anything being taken from the array while the sort is in progress?
All this is happening in the APPLICATION
scope on a CF 8 Enterprise server.
Thanks in advance for any help.
Ciaran