41
loading...
This website collects cookies to deliver better user experience
libc
. In particular, you should avoid global state.libulid
. And then I discovered that I knew almost nothing about writing a C library.libulid
ready.rand()
function from libc
. rand()
requires a seed()
function to be called that initializes a global random seed.ulid_seed()
and then ulid_new()
later on. This created two issues. First it was horrible to work with. Secondly, it wasn't thread safe. The function rand()
is not reentrant, since it uses hidden state that is modified on each call. This might just be the seed to be used by the next call, or it might be something more elaborate. In order to get reproducible behavior in a threaded application, this state must be made explicit; this can be done using the reentrant function rand_r()
.
libc
documentation. ulid_ctx
object that stores the random seed and pass a pointer to it when creating a new ULID._t
suffix to all of the types that I created. It turns out that this convention is reserved by POSIX for its types. ulid()