Skip to content

thread safety #18

Description

@LytixDev

Some data structures should perhaps be thread safe?

For example the hashmap implementation should have a way to ensure it is safe to use with multiple threads.
It could be as simple as having one single mutex locking the entire hashmap. We could also have a mutex that only locks on hashmap_put.

In order to not add the overhead of thread safety when its not needed, the user should define whether or not they want the implementation to be thread safe.

// user writes
#define HASHMAP_THREAD_SAFE

...

struct hashmap_t {
    struct bucket_t *buckets;
    uint32_t size_log2;
    size_t len;
#ifdef HASHMAP_THREAD_SAFE
   mutex_t lock;
#endif
};

void hashmap_put()
{
#ifdef HASHMAP_THREAD_SAFE
    // acquire lock
#endif

   / / code

#ifdef HASHMAP_THREAD_SAFE
    // release lock
#endif
}


s

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions