-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't use threadid
in e.g. BBCode
#391
Comments
So the specific bit of a code with a problem here is this: const _id_count::Dict{Int,Int32} = Dict{Int,Int32}()
"""
ID()
An `ID` (read: unique name) is just a wrapper around an `Int32`. Uniqueness is ensured via a
global counter, which is incremented each time that an `ID` is created.
This counter can be reset using `seed_id!` if you need to ensure deterministic `ID`s are
produced, in the same way that seed for random number generators can be set.
"""
struct ID
id::Int32
function ID()
current_thread_id = Threads.threadid()
id_count = get(_id_count, current_thread_id, Int32(0))
_id_count[current_thread_id] = id_count + Int32(1)
return new(id_count)
end
end which can be found here. I think the only problem that was causing problems here previously was race conditions, in which multiple threads would attempt to access and increment the This doesn't solve the determinism problem though - it's quite helpful when debugging to have it such that each time you build the same rule, you get the same set of Would indexing by |
TBH I'm not completely comfortable with the task/thread distinction, I just signaled it because I had the blog post title in mind |
Cool. I'll ask around a bit. |
https://julialang.org/blog/2023/07/PSA-dont-use-threadid/
The text was updated successfully, but these errors were encountered: