Live data from Hacker News

A Universal I/O Abstraction for C++ (2020)

cor3ntin.github.io

51–60 of 88 posts

Re: A Universal I/O Abstraction for C++ (2020)

#51

In the end the overall design looks like a semi-reified asynchronous dataflow programming API based on coroutines. I think that it would be useful to consider the existing (very very very large) body of research on dataflow PL and APIs; e.g. check this paper from 1982 which talks about dataflow, coroutines, for handling file operations: - https://scholarship.claremont.edu/cgi/viewcontent.cgi?articl... More recent pap…

> if we know that a set of tasks are dependent on each other in ways that aren't visible on the source code, but are known to the programmers, it would make sense to schedule them on a queue in their own thread Why it would make sense? In my experience, dedicated threads only makes sense in very specific use cases. Like dealing with APIs which have thread affinity, or when you want OS to prioritize stuff. Generally,…

> In my experience, dedicated threads only makes sense in very specific use cases. Like dealing with APIs which have thread affinity, or when you want OS to prioritize stuff.

well, yes, those are things that happen fairly often. e.g. there's a lot of work on optimizing code for various arm big.LITTLE things, where you have some algorithm that you want to make sure runs on the "big" cores.

Re: A Universal I/O Abstraction for C++ (2020)

#52

Earlier quoted context omitted.

> if we know that a set of tasks are dependent on each other in ways that aren't visible on the source code, but are known to the programmers, it would make sense to schedule them on a queue in their own thread Why it would make sense? In my experience, dedicated threads only makes sense in very specific use cases. Like dealing with APIs which have thread affinity, or when you want OS to prioritize stuff. Generally,…

> In my experience, dedicated threads only makes sense in very specific use cases. Like dealing with APIs which have thread affinity, or when you want OS to prioritize stuff. well, yes, those are things that happen fairly often. e.g. there's a lot of work on optimizing code for various arm big.LITTLE things, where you have some algorithm that you want to make sure runs on the "big" cores.

Can’t you use two shared thread pools, with threads affinity set to the big and little parts of the CPU, respectively?

I think for most use cases runtime scheduling is better than compile-time one. Because other processes sharing the hardware, and because tasks take unpredictable time, depends on almost everything including ambient temperature. Not to mention compilers don’t generally know count of cores, outside of a few niches like embedded, iOS and consoles games.

Re: A Universal I/O Abstraction for C++ (2020)

#53

In the end the overall design looks like a semi-reified asynchronous dataflow programming API based on coroutines. I think that it would be useful to consider the existing (very very very large) body of research on dataflow PL and APIs; e.g. check this paper from 1982 which talks about dataflow, coroutines, for handling file operations: - https://scholarship.claremont.edu/cgi/viewcontent.cgi?articl... More recent pap…

> semi-reified asynchronous dataflow programming API based on coroutines

Gesundheit!

Re: A Universal I/O Abstraction for C++ (2020)

#54

Earlier quoted context omitted.

Hum, in principle you can do arbitrary compile time transformations to the datagraph before submitting it via metaprogramming. If you really want you could even convert the graph (fully or partially) to a runtime representation. The core of the proposals are not about specific classes or functions other than some default algorithm implementations. Instead they are mostly about defining concepts and protocols so that…

> Hum, in principle you can do arbitrary compile time transformations to the datagraph before submitting it via metaprogramming. I would find that to be great, but I don't understand how. In e.g. while(i) { co_await sch.schedule(std::chrono::milliseconds(100)); co_await w.write(--i); } how can you get a meaningful "graph" object out of that, e.g. [wait 100] -> [write 9] -> [wait 100] -> [write 8] -> ... without actua…

The proposed async "framework" happens to work well with coroutines, but they are not required (and infact most of the papers on the topic deal with them only in passing). You can build the async graph as an expression template and if you want, each operation (including the while loop) can be expressed as a different type.

I don't think coroutines provide (yet) enough introspection to break them down in the same way.

Re: A Universal I/O Abstraction for C++ (2020)

#55

Earlier quoted context omitted.

> Hum, in principle you can do arbitrary compile time transformations to the datagraph before submitting it via metaprogramming. I would find that to be great, but I don't understand how. In e.g. while(i) { co_await sch.schedule(std::chrono::milliseconds(100)); co_await w.write(--i); } how can you get a meaningful "graph" object out of that, e.g. [wait 100] -> [write 9] -> [wait 100] -> [write 8] -> ... without actua…

The proposed async "framework" happens to work well with coroutines, but they are not required (and infact most of the papers on the topic deal with them only in passing). You can build the async graph as an expression template and if you want, each operation (including the while loop) can be expressed as a different type. I don't think coroutines provide (yet) enough introspection to break them down in the same way.

I see, that solves it then. Great !

Re: A Universal I/O Abstraction for C++ (2020)

#56
post #49
post #28

Earlier quoted context omitted.

Problem was, real world programming in Lisp was not simple.

Just like real world programming in C is hardly memory corruption free, and only around 10% of survey answers keep asserting to use any kind of memory assurance tooling.

The other 90% are the better than average programmers who don't need such training wheels. /s

Re: A Universal I/O Abstraction for C++ (2020)

#57
post #11
post #7

Too bad C++ is the most terrible thing since forever. https://twitter.com/Cor3ntin/status/1383875999033565194?s=20

All those "orange site bad" comments lol

Yeah, "orange site" comments on Twitter are an interesting entertainment genre in general, if you're into "a visit to the bizarro world" type of humor :).

Re: A Universal I/O Abstraction for C++ (2020)

#58
post #27

Earlier quoted context omitted.

Have been programming in C (and then C++), like, forever. Hardly any memory corruption issues. Yes, you have to be a little more disciplined and pay attention to things. Being distracted certainly does not help.

A significant fraction of major security vulnerabilities in C/C++ codebases relate to memory-management bugs.

How old is the code though? It's actually really hard to get modern C++ wrong

Re: A Universal I/O Abstraction for C++ (2020)

#59

C++'s networking support is one of its greatest shortcomings. If I had the choice, I'd never use ASIO again and just use libuv. Coroutines look interesting, I just need to get my head around them. All code examples I've seen, just as with ASIO, deal with the happy path only. For example, there's hardly a mention of timeouts and the faff ASIO makes you do to get them to work. If there's no 'read(..., timeout)' functio…

Boost Beast, which is built on ASIO, has support for timeouts[0], as well as HTTP 1.1 and Websockets. The examples in the Beast tree do do some pretty complex stuff elegantly, like a multi-client chat server[1], so it's possible.

There's also nghttp2_asio, built on nghttp2, which supports HTTP/2[2].

Overall I agree though that ASIO is a very complex and very low level, and it's a lot of work to use it well.

Sometimes it's easiest just to use libcurl.

[0] https://www.boost.org/doc/libs/1_76_0/libs/beast/doc/html/be...

[1] https://www.boost.org/doc/libs/1_70_0/libs/beast/example/web...

[2] http://nghttp2.org/documentation/libnghttp2_asio.html

Re: A Universal I/O Abstraction for C++ (2020)

#60

C++'s networking support is one of its greatest shortcomings. If I had the choice, I'd never use ASIO again and just use libuv. Coroutines look interesting, I just need to get my head around them. All code examples I've seen, just as with ASIO, deal with the happy path only. For example, there's hardly a mention of timeouts and the faff ASIO makes you do to get them to work. If there's no 'read(..., timeout)' functio…

You might love evpp instead ASIO. It's just pain to install it but once you do it's a heaven. As for HTTP parsing, llhttp does great job. It however lack multipart parsing.

Boost.Beast has its own HTTP parser[0], during the development of which Vinnie Falco (the principle author of Beast) found many bugs/inconsistencies in Node.js's own parser[1].

Personally I'd rather use this than something based on Node.js http-parser.

[0] https://www.boost.org/doc/libs/develop/libs/beast/doc/html/b...

[1] https://github.com/nodejs/http-parser/issues?q=is%3Aissue+au...

Post reply on HN