Skip to content

Add optional count argument to Semaphore::post - #93605

Merged
akien-mga merged 1 commit into
godotengine:masterfrom
radiantgurl:thread-barriers
Aug 27, 2024
Merged

akien-mga merged 1 commit into
godotengine:masterfrom
radiantgurl:thread-barriers

Conversation

@radiantgurl

@radiantgurl radiantgurl commented Jun 25, 2024 •

Copy link
Copy Markdown
Contributor

Implements a new optional argument in Semaphore.post to allow resuming multiple threads at once.

@radiantgurl
radiantgurl force-pushed the thread-barriers branch 2 times, most recently from 0076121 to 96f75a8 Compare June 25, 2024 18:56
@radiantgurl
radiantgurl marked this pull request as ready for review June 25, 2024 18:56
@radiantgurl
radiantgurl requested review from a team as code owners June 25, 2024 18:56
@Chaosus Chaosus added this to the 4.x milestone Jun 25, 2024
@Chaosus
Chaosus requested a review from RandomShaper June 25, 2024 19:28
@Chaosus Chaosus changed the title Add optional count argument to Sempahore::post Add optional count argument to Semaphore::post Jun 25, 2024
Comment thread core/core_bind.cpp Outdated
Comment thread core/core_bind.cpp Outdated
@Mickeon

Mickeon commented Jun 25, 2024

Copy link
Copy Markdown
Member

May I ask in what occasion would this be useful? It is a relatively innocent change, but it's still worth knowing why it would need to be done.

@radiantgurl

Copy link
Copy Markdown
Contributor Author

It's just so you dont have to do a for loop anymore to resume more and more threads, and it would be way more optimized than constantly locking and unlocking the mutex, adding 1 to the count and running notify_one.

Comment thread core/core_bind.compat.inc Outdated
Comment thread core/core_bind.compat.inc Outdated
Comment thread core/core_bind.compat.inc Outdated
Comment thread core/core_bind.cpp Outdated
Comment thread core/core_bind.cpp Outdated
Comment thread core/core_bind.cpp Outdated
Comment thread core/core_bind.h Outdated
Comment thread core/core_bind.h Outdated

@RandomShaper RandomShaper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Leaving my approval on the added API. This needs to have the compatibility stuff fixed (which I'm not very familiar with) fixed per @AThousandShips comments before merging.

@Bromeon

Bromeon commented Jun 26, 2024

Copy link
Copy Markdown
Contributor

Was a named method considered (post_n or something)? Not sure what's the usual API design in such cases.

@radiantgurl
radiantgurl force-pushed the thread-barriers branch 2 times, most recently from e62d00d to de4386b Compare June 26, 2024 15:30
Comment thread core/core_bind.h Outdated
Comment thread misc/extension_api_validation/4.2-stable.expected Outdated

@Mickeon Mickeon left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is count as the name of the parameter completely fine? Yyyyeah, I'm sure it'll be fine.

Comment thread doc/classes/Semaphore.xml Outdated
Comment thread doc/classes/Semaphore.xml Outdated
@AThousandShips

Copy link
Copy Markdown
Member

The co-author additions for just reviews aren't necessary by the way, feel free to remove them

@radiantgurl
radiantgurl force-pushed the thread-barriers branch 2 times, most recently from 9f8db92 to 272bb73 Compare August 27, 2024 03:12
Co-authored-by: RandomShaper <RandomShaper@users.noreply.github.com>
Co-authored-by: A Thousand Ships (she/her) <96648715+AThousandShips@users.noreply.github.com>
Co-authored-by: Mickeon <Mickeon@users.noreply.github.com>
@Mickeon Mickeon modified the milestones: 4.x, 4.4 Aug 27, 2024
@Mickeon

Mickeon commented Aug 27, 2024

Copy link
Copy Markdown
Member

I think we can safely push this to 4.4 . Still waiting on the GDExtension and DotNet teams for review.

@akien-mga
akien-mga merged commit 8ae2c3a into godotengine:master Aug 27, 2024
@akien-mga

Copy link
Copy Markdown
Member

Thanks!

@RandomShaper

Copy link
Copy Markdown
Member

I've found something a bit concerning... One of my PRs was tested against 4.3, where it worked. On master it broke. The reason was that on master I had to add .bind(1) to a Callable to core_bind::Semaphore::post(); otherwise, I would get too-few-args error. On 4.3, adding the .bind(1) makes the code fail with too-many-args error. Therefore, there's a compat breakage here. Or is the reason that we have an issue with the binding-call system not honoring the default arg in case the .bind(1) is missing?

@AThousandShips

Copy link
Copy Markdown
Member

The callable_mp system doesn't know anything about bound methods so it can't honor the default argument, and in c++ default arguments are a kind of decoration and won't actually be relevant to the method pointer itself, so it's not trivial to handle that without somehow utilizing the method bind system

@AThousandShips

AThousandShips commented Sep 17, 2024 •

Copy link
Copy Markdown
Member

It's been discussed (forget where) and I've looked at some tricks to make it easier by creating a custom callable from a MethodBind but haven't done much on it as it's a bit convoluted, and would require fetching the method (also wouldn't work with non-bound methods, though we could use the bind without using the ClassDB system)

But will see about opening some issue to track it and look at ideas when I can

@radiantgurl
radiantgurl deleted the thread-barriers branch September 17, 2024 12:42
@Mickeon

Mickeon commented Sep 17, 2024

Copy link
Copy Markdown
Member

If this is a severe problem reverting this PR should be fine as it's a relatively small Quality-of-Life feature.

BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
Add optional count argument to `Semaphore::post`
BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
Add optional count argument to `Semaphore::post`
wangshucheng pushed a commit to wangshucheng/godot that referenced this pull request Aug 27, 2026
Add optional count argument to `Semaphore::post`
Shane-Gadsby pushed a commit to Shane-Gadsby/godotwebgpu that referenced this pull request Sep 21, 2026
Add optional count argument to `Semaphore::post`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants