8000 Suggestion on shared_ptr parameter passing in examples · Issue #296 · jbaldwin/libcoro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Suggestion on shared_ptr parameter passing in examples #296

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

Closed
Sola1Go opened this issue Feb 11, 2025 · 3 comments · Fixed by #303
Closed

Suggestion on shared_ptr parameter passing in examples #296

Sola1Go opened this issue Feb 11, 2025 · 3 comments · Fixed by #303
Labels
enhancement New feature or request

Comments

@Sola1Go
Copy link
Contributor
Sola1Go commented Feb 11, 2025

I'd like to discuss the parameter passing style of shared_ptr in examples and test cases. Through my learning journey, I noticed that some code snippets (e.g., those using std::shared_ptr<coro::io_scheduler>&) employ reference passing for better performance. While this approach works perfectly in scenarios with straightforward lifetime management, I'm concerned it could be potentially misleading for newcomers.

The C++ Core Guidelines passing shared_ptr by value when ownership sharing is needed, as it explicitly maintains the reference count. This becomes particularly important in coroutine contexts where suspended coroutines might outlive their frame objects - value semantics provide clearer ownership tracking.

Would you consider demonstrating the value-passing approach in examples as the default practice? I understand the reference approach might be intentional for specific optimizations, and I'd appreciate any insights you could share. If there are nuances I've misunderstood regarding the project's design philosophy, I'd be grateful for your guidance.

Regards.

@jbaldwin
Copy link
Owner

Hello @Sola1Go ,

I think this is a good idea, you are right that when I originally created these examples a lot of them can work with references since the outer scope that the scheduler is created in outlives the coroutine. But I can definitely see how this is misleading for a real world example. I think using std::shared_ptr appropriately with copy semantics in the examples is the right direction.

Would you be willing to take a stab at updating them with a PR? If not I will try and get to it when I have some time since I do think this is the right move but might be a bit of time.

@jbaldwin jbaldwin added the enhancement New feature or request label Feb 15, 2025
@Sola1Go
Copy link
Contributor Author
Sola1Go commented Feb 21, 2025

I'm really glad you agree with my suggestion. PR: #303

@jbaldwin jbaldwin linked a pull request Feb 21, 2025 that will close this issue
@jbaldwin
Copy link
Owner

Thanks for opening the PR, it looked good to me so I went ahead and merged it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0