Closed frederikhors closed 2 years ago
Can you help me understand what does this mean and how to write SAFE code for concurrent use with libraries such ent or gqlgen?
Here are a few links relevant to the topic of thread safe random number generation in Go:
If you don't care that there is contention on a locked random number generator across go-routines, use this: https://pkg.go.dev/golang.org/x/exp/rand#example-LockedSource. I will update the README with this recommendation, since it seems most users of ulid
don't want to define their own thread safe entropy source, nor manage a sync.Pool
.
If you find there's too much contention in your program in production (via profiling with pprof
), you can implement the sync.Pool
solution.
I opened https://github.com/oklog/ulid/pull/80 to improve the README.
As a follow up, here's a proposal for a ulid.Make()
function that has sane defaults and is safe for concurrent use: https://github.com/oklog/ulid/pull/81
The method described here is really fast! Can we use it with ulid?
The method described here is really fast! Can we use it with ulid?
Of course. Just create an io.Reader that uses this as a source of entropy.
The method described here is really fast! Can we use it with ulid?
Of course. Just create an io.Reader that uses this as a source of entropy.
Can you show me an example please?
Merged #81
I just asked this question on SO. I'm posting this here too both for me and for for future "researchers".
I'm trying to use for the first time the ulid package.
In their README they say:
Can you help me understand what does this mean and how to write SAFE code for concurrent use with libraries such ent or gqlgen?
Example: I'm using the below code in my app to generate new IDs (sometimes even many of them in the same millisecond which is fine for
ulid
).Is this a safe way to use the package?
Can you help me better understand?