Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semaphore plus #667

Merged
merged 1 commit into from
Dec 19, 2024
Merged

semaphore plus #667

merged 1 commit into from
Dec 19, 2024

Conversation

lihuiba
Copy link
Collaborator

@lihuiba lihuiba commented Dec 17, 2024

(1) add an option for in-order resume of threads (by default not);
(2) avoid thundering herd of threads whose needs are not met;

thread/thread.h Outdated Show resolved Hide resolved
@lihuiba lihuiba changed the title semaphore plus: semaphore plus Dec 18, 2024
auto cnt = m_count.fetch_add(count) + count;
if (!q.th) return 0;
if (cnt >= q.th->semaphore_count) {
do_resume: resume_one();
Copy link
Collaborator Author

@lihuiba lihuiba Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following loop depends on the condition that q.th has been checked. The loop starts from the 2nd element, and uses q.th as the end.

@lihuiba lihuiba force-pushed the semaphore_plus branch 3 times, most recently from 405c401 to e7eff91 Compare December 19, 2024 00:09
(1) add an option for in-order resume of threads (by default not);
(2) avoid thundering herd of threads whose needs are not met;
Copy link
Collaborator

@Coldwings Coldwings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lihuiba lihuiba merged commit b1e7ab3 into alibaba:main Dec 19, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants