Shared resource in multithreading environment #1214
-
let's say i'm running an REST-event-loop on the main thread. It has a PUT that updates a map on the same thread. So far everything is working fine. Now what happens if this map is being accessed by other threads. Will it produce undesirable behavior? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Lock the map. If it's tiled you only have to lock the tiles accessed. Or shard it. uWS runs on "regular" threads and those can access anything that's properly locked. |
Beta Was this translation helpful? Give feedback.
-
One event loop with multiple threads means any multi-threaded map will work. You could keep it simple and just lock the map but why do that when you can just link an entire new non-standard library to do it for you? 🤔🤔🤔 Pick your poison: |
Beta Was this translation helpful? Give feedback.
Lock the map. If it's tiled you only have to lock the tiles accessed. Or shard it. uWS runs on "regular" threads and those can access anything that's properly locked.