struct lfds700_misc_prng_state

From liblfds.org
Jump to navigation Jump to search

Source File

└───liblfds700
    └───inc
        └───liblfds700
                lfds700_misc.h

Opaque Structure

struct lfds700_misc_prng_state;

Alignment

Allocations should be LFDS700_PAL_CACHE_LINE_LENGTH_IN_BYTES aligned, but this is not mandatory. Not doing so will result in what will probably be a small performance loss.

Notes

This structure represents the state of a fast, high-quality random number generator. The library needs this for exponential back-off from lock-free operation collisions, which in turn is needed to ameilorate the issue of livelock.

Please see Lock-Free Exponential Backoff and Randon Number Generation for a proper explanation of all this.

The long and short of it though is that this structure is single-threaded, i.e. there must be one per thread, and that many data structure functions require this an argument. All that needs to be done is that the store for it must exist (it is often easy to simply place this on the stack in the thread function) and that it must be initialized, by a call to lfds700_misc_prng_init.

After that, nothing else is done with it, except to pass it into such functions as require it. No cleanup is required.

It is important for performance to allocate this structure (be in on the stack, heap, etc) on a cache-line boundary.

This can be done on the stack using the liblfds porting abstraction layer, like so;

struct lfds700_misc_prng_state LFDS700_PAL_ALIGN( LFDS700_PAL_CACHE_LINE_LENGTH_IN_BYTES )
  ps;

If this is not done, nothing will break, but performnce will suffer, probably only slightly.

For aligned heap allocations, an aligned malloc is normally provided by the operating system.

See Also