Skip to content

Question about the implementation of photon::mutex #976

@Yriuns

Description

@Yriuns

After checking the source code, I believe that photo::mutex should follow a FIFO policy. This means that the next thread to acquire the lock will definitely be the first thread in the waiting queue. This implies that there must be at least one wake-up process between the time when the thread holding the lock releases it and the time when the next thread acquires the lock and continues to execute.

In contrast, the mutex implementation in brpc allows any bthread to preempt the lock after it is unlocked, so there is only one CAS operation between the time when the thread holding the lock releases it and the time when the next thread acquires the lock and continues to execute.

Why didn't photon adopt this kind of implementation? I think such an implementation would perform much better in cases where the critical section is small and contention is heavy.

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