hello, i have a []std.ArrayList(T), where each element in the array should be only accessed by one thread.
i fill the arraylists in a async/concurrent function, i would like to get a unique ID for the current thread working on the provided function. the thread uses this to index into the array, and append to the arraylist there.
the slice is equal in length to CPU count.
1 Like
Io abstracts over the unit of concurrency, which may or may not be threads. It provides no way to get an ID of the concurrency unit as such a thing might not exist, and if it does, it may not correspond to a thread.
You can implement your own ID’s, passing them as args to the function being called through async/concurrent.
Alternatively you could give the function a ptr to the element, then it does not need an ID or access to the whole shared slice which might otherwise be accessed incorrectly on accident.
2 Likes