Suppose a coroutine containing the following code is applied (
%) to a list containing actors that seek items in the world. If they find one, they ‘pick it up’ by destroying it. Without knowledge of the underlying concurrency model (assuming one exists) I cannot knowingly prevent instances where one actor is mutating a list that another actor is currently operating on. You can probably see where I’m headed.
// Reached the item. 'Pick it up' if pickup_items.find?[item = criteria]; !idx [ !matched_item : pickup_items.pop_at(idx) matched_item.destroy_sk_actor ]
Is this code at risk for destroying an element in a list that another actor assumes still exists and therefore amounts to something like a segfault?
It is insufficient to check if matched_item is valid, because the idx that one actor thought corresponded to an item now points to a different item. Classic synchronization problem here.
But if each actor is acting in a linear, sequential manner, then I think I’m safe, because the list of pickup items will have updated by the time the next actor has a chance to respond.