

Implement a thread-safe array wrapper in Swift that supports concurrent access from multiple threads. The array should expose common operations such as reading an element, appending a value, removing an element, and returning a snapshot of the current contents. Ensure that reads do not observe partially written state and that writes are serialized correctly.
Example 1:
Input: append(1), append(2), get(0), snapshot()
Output: 1, [1, 2]
Explanation: Concurrent access should still behave as if operations were applied safely in order.
Example 2:
Input: append(10), append(20), remove(at: 0), get(0)
Output: 20
Explanation: After removing the first element, the remaining element is returned safely.
Implement a thread-safe array wrapper in Swift that supports concurrent access from multiple threads. The array should expose common operations such as reading an element, appending a value, removing an element, and returning a snapshot of the current contents. Ensure that reads do not observe partially written state and that writes are serialized correctly.
Example 1:
Input: append(1), append(2), get(0), snapshot()
Output: 1, [1, 2]
Explanation: Concurrent access should still behave as if operations were applied safely in order.
Example 2:
Input: append(10), append(20), remove(at: 0), get(0)
Output: 20
Explanation: After removing the first element, the remaining element is returned safely.