Thread-safe list

Hello,

I’m at a stage where I’m trying to create code that will work with multiple threads. Each thread will be controlled by a global task list. It will frequently add and remove elements from this list.

During testing, it seems like the code is getting lost. I’ve read about multithreading issues, and it seems that lists are not thread-safe. Can you please suggest how to create code that is thread-safe, and in cases where one thread will be adding/removing something from the global list, another will wait for these operations?

Should I create something like a semaphore and a coroutine with yield, or are there any ready-made methods for multiple threads to work on a global list safely?