#Concurrent map write

16 messages · Page 1 of 1 (latest)

unreal cloud
#

When a map is passed as an argument to a function running in a go routine and then passed to a function in another go routine, are they the same map? Like will modifying one affect the other? Because in my program, there is a map being passed down many times recursively but I don't think it should be being written do concurrently. Is there a way to ensure that I'm passing down a copy of the map?

hexed mortar
#

yes they’re the same map

unreal cloud
hexed mortar
#

let’s take a couple steps back, what are you trying to accomplish with this

unreal cloud
#

so you see, the program starts off by getting a list of rooms it is currently in, it adds in in a map of type map[string]bool so it doesn't have to go through an entire slice to see if it's in a room. after it adds it to that map, it calls another function in a go routine (using the map that it created) that scans that room for mentions of more rooms, which it then passes into the same function again in another go routine (after checking that map to see what rooms it is in), using that same map, which it modified in that function. It will just do this until it runs out of mentions of rooms. So like a web crawler basically.

unreal cloud
hexed mortar
#

ah yeah, you’re not going to want to copy that map as it’s going to not be too useful if each goroutine is operating on its own copy

unreal cloud
#

mutex?

unreal cloud
hexed mortar
#

yep, you’d wrap the map in a mutex of some sort

unreal cloud
#

alr bet

unreal cloud
hexed mortar
#

yep that would work

unreal cloud
#

yessir thx

#

alr done

#

welp imma close thread