Live data from Hacker News

Building a shared vision for Async Rust

blog.rust-lang.org

11–20 of 139 posts

Re: Building a shared vision for Async Rust

#11
post #9
post #8

I admire the passion, but I’m not sure why I would want Rust at all, not just async. When I want memory safety, async-await, I/O performance, easy multithreading, I write C#. When I want performance of CPU bound code, or lots of integration with native libraries/APIs, I write C++. Sometimes I want both in the same software, compile C++ code into a DLL (or shared library on Linux), and consume it from C#. I don’t have…

Do you have any good resources on writing dlls to consume via .net like you’re talking about ? How do you deal with the managed memory when using the gc from .net

> Do you have any good resources on writing dlls to consume via .net like you’re talking about?

For C APIs i.e. functions, structures and strings, the good resource is Microsoft documentation, the support is built-in, see “Consuming Unmanaged DLL Functions” section: https://docs.microsoft.com/en-us/dotnet/framework/interop/

For COM APIs i.e. sharing objects around see this library + demos: https://github.com/Const-me/ComLightInterop It’s only really needed on Linux because the desktop version of the framework has COM support already built-in, but it can be used for cross-platform things just fine, I tested that quite well i.e. not just with these simple demos.

> How do you deal with the managed memory when using the gc from .net

Most of the time, automatically.

When you calling C++ from C#, the runtime automatically pins arguments like strings or arrays. Pinning means until the C++ function returns, .NET GC won’t touch these things. This doesn’t normally make any copies: C++ will receive raw pointers/native references to the .NET objects.

Sometimes you do want to retain C# objects from C++ or vice versa i.e. keep them alive after the function/method returns. An idiomatic solution for these use cases is COM interop. IUnknown interface (a base interface for the rest of COM interfaces) allows to retain/release things across languages.

Re: Building a shared vision for Async Rust

#12
post #9
post #8

I admire the passion, but I’m not sure why I would want Rust at all, not just async. When I want memory safety, async-await, I/O performance, easy multithreading, I write C#. When I want performance of CPU bound code, or lots of integration with native libraries/APIs, I write C++. Sometimes I want both in the same software, compile C++ code into a DLL (or shared library on Linux), and consume it from C#. I don’t have…

Do you have any good resources on writing dlls to consume via .net like you’re talking about ? How do you deal with the managed memory when using the gc from .net

On Windows, just use C++/CLI or COM.

Contrary to urban myths, all major APIs introduced since Vista are mostly COM.

On other platforms, P/Invoke provides a very straightforward way to bind into C ABI.

You can manage native memory via "using" (since C# 8.0 you don't even need to implement IDisposable), or SafeHandles.

Re: Building a shared vision for Async Rust

#13
post #7

Is there any thought to including a default executor in the standard library? I think it's kind of an obstacle for beginners when the language/stdlib provide all the tools to write async code, but not to run it. I saw discussed in this talk the intent in allowing developers to provide their own executor based on the specifics of their use case: https://youtu.be/NNwK5ZPAJCk?t=1107 This makes sense to me; however, I fe…

[deleted]

Re: Building a shared vision for Async Rust

#14
post #7

Is there any thought to including a default executor in the standard library? I think it's kind of an obstacle for beginners when the language/stdlib provide all the tools to write async code, but not to run it. I saw discussed in this talk the intent in allowing developers to provide their own executor based on the specifics of their use case: https://youtu.be/NNwK5ZPAJCk?t=1107 This makes sense to me; however, I fe…

It was suggested in a PR, which was then punted into RFC territory. I’m not aware of anyone actively pursuing an RFC at this time.

Correctly if I'm wrong, but IIRC low-level futures are very dependent on executor? I think you actually told me that, but that was back in futures 0.1 era.

Re: Building a shared vision for Async Rust

#15
post #8

I admire the passion, but I’m not sure why I would want Rust at all, not just async. When I want memory safety, async-await, I/O performance, easy multithreading, I write C#. When I want performance of CPU bound code, or lots of integration with native libraries/APIs, I write C++. Sometimes I want both in the same software, compile C++ code into a DLL (or shared library on Linux), and consume it from C#. I don’t have…

Not everyone needs to use Rust. If you don’t have a desire to, that’s 1000% okay!

I am not sure why you’re downvoted. Maybe it’s because it’s sorta kinda off topic?

Re: Building a shared vision for Async Rust

#16

Earlier quoted context omitted.

It was suggested in a PR, which was then punted into RFC territory. I’m not aware of anyone actively pursuing an RFC at this time.

Correctly if I'm wrong, but IIRC low-level futures are very dependent on executor? I think you actually told me that, but that was back in futures 0.1 era.

“Leaf” futures often are, yes. This term (coming from like, a tree) is a tad more descriptive than “low level” IMHO. We have yet to achieve a fully agnostic solution everywhere. That’s part of what work in this area is trying to figure out, as I understand it.

Re: Building a shared vision for Async Rust

#17
post #8

I admire the passion, but I’m not sure why I would want Rust at all, not just async. When I want memory safety, async-await, I/O performance, easy multithreading, I write C#. When I want performance of CPU bound code, or lots of integration with native libraries/APIs, I write C++. Sometimes I want both in the same software, compile C++ code into a DLL (or shared library on Linux), and consume it from C#. I don’t have…

Not everyone needs to use Rust. If you don’t have a desire to, that’s 1000% okay! I am not sure why you’re downvoted. Maybe it’s because it’s sorta kinda off topic?

> Maybe it’s because it’s sorta kinda off topic?

Could be, but I find this strange as well. I don’t remember a discussion on HN about any programming language at all without people commenting about Rust. Don’t remember them being downvoted.

P.S. As to why I wrote the comment — the article invited the “status quo” stories, so I decided to share my perspective.

Re: Building a shared vision for Async Rust

#18

Earlier quoted context omitted.

It was suggested in a PR, which was then punted into RFC territory. I’m not aware of anyone actively pursuing an RFC at this time.

Correctly if I'm wrong, but IIRC low-level futures are very dependent on executor? I think you actually told me that, but that was back in futures 0.1 era.

You're probably thinking of IO streams that ultimately have their wakers woken via epoll - they do this by expecting there to be some IO reactor running the epoll loop that they can register their fd+waker with. They don't directly depend on a specific executor, just on the presence of a specific IO reactor. For something specific like tokio's IO streams, it would require tokio to provide its IO reactor as a standalone thing that could be run independent of using its `Runtime` executor.

Re: Building a shared vision for Async Rust

#19

Earlier quoted context omitted.

Not everyone needs to use Rust. If you don’t have a desire to, that’s 1000% okay! I am not sure why you’re downvoted. Maybe it’s because it’s sorta kinda off topic?

> Maybe it’s because it’s sorta kinda off topic? Could be, but I find this strange as well. I don’t remember a discussion on HN about any programming language at all without people commenting about Rust. Don’t remember them being downvoted. P.S. As to why I wrote the comment — the article invited the “status quo” stories, so I decided to share my perspective.

They get downvoted and yelled at too. I’ve seen it :)

Re: Building a shared vision for Async Rust

#20
post #6

I like the approach that steps back and looks at usage scenarios. Not everything has to be solved by changing the language itself; it may be a matter of better tooling or teaching materials. For example, the recent "async doesn't work" blog post was centered around confusion between `fn()` pointer and `Fn()` trait, and misuse of temporary `&mut` where `Arc ` was required. If the compiler was smart enough to suggest t…

That wasn't confusion, that was the point. If there's confusion it's in people having different conceptions of what async language constructs should provide, which color their criticisms and rationales.
Post reply on HN