Skip to content

thread.h mutex recursive on Windows but not pthread #68

@Photosounder

Description

@Photosounder

In thread.h thread_mutex_lock() doesn't behave the same on Windows as on Linux/macOS. On Windows it is recursive, meaning you can double-lock a mutex on the same thread, but on Linux as it is it will deadlock. My personal solution is making the pthread one also recursive by replacing pthread_mutex_init( (pthread_mutex_t*) mutex, NULL ); with:

	pthread_mutexattr_t ma;
	pthread_mutexattr_init(&ma);
	pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init((pthread_mutex_t *) mutex, &ma);
	pthread_mutexattr_destroy(&ma);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions