Thread safe?

My app has a dictionary as a property.

Can that same dictionary be accessed by two different threads ‘safely’?

Cooperative or preemptive threads?

Read or write?

Cooperative threads would work fine.

Preemptive threads should be able to read at the same time. But writing needs a mutex to synchronize access.

2 Likes

I think additions and searching is fine, but i worry about deletions,…

If you’re worried use cooperative threading. It is time tested and much easier to use for Citizen Developer level.

preemptive threads

this kind is useful if you will use much or all cpu cores.

https://documentation.xojo.com/api/language/threading/thread.html

Dictionary code is a bit complex, several tasks during an action, not sure if the code is re-entrant, so, if Xojo did not take care about the problem (I do expect they did it) you should protect both set() and get() until the completion (inside a Critical Section)
Maybe it is already at the core code, maybe a little note in the docs could be done for both cases, if already protected or not.

1 Like