Skip to content

Question: Potential issue with error mutex? #2542

Closed
@hypatia-of-sva

Description

@hypatia-of-sva

Hello GLFW team,

I was looking through the code of GLFW 3.4 and was a bit confused by the following lines in _glfwInputError in init.c:

            error = _glfw_calloc(1, sizeof(_GLFWerror));
            _glfwPlatformSetTls(&_glfw.errorSlot, error);
            _glfwPlatformLockMutex(&_glfw.errorLock);
            error->next = _glfw.errorListHead;
            _glfw.errorListHead = error;
            _glfwPlatformUnlockMutex(&_glfw.errorLock);

It seems like the value of the at the errorslot is set to the local allocation before the mutex is set. If I understand it correctly, the slot should be locked by the mutex. Was this just a confusion on my part? I would have expected something like:

            error = _glfw_calloc(1, sizeof(_GLFWerror));
            _glfwPlatformLockMutex(&_glfw.errorLock);
            _glfwPlatformSetTls(&_glfw.errorSlot, error);
            error->next = _glfw.errorListHead;
            _glfw.errorListHead = error;
            _glfwPlatformUnlockMutex(&_glfw.errorLock);

instead. If this is intentional, maybe a comment here would also help other people trying to understand and/or refactor the GLFW code for their own needs.

With regards,
Hypatia of Sva.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions