Fully fledged coroutines let you save and resume execution in place. The main advantage is readability of conditional/looping control flow, which tends to quickly devolve into a mess in callback style code.
7,982 karma · joined January 21, 2008
While looking for the next big thing, I do contract/consulting work; I prefer lower-level stuff, such as device drivers/kernel hacking, real-time graphics and game tech.).
You're welcome to email me about anything, and I promise to reply if you stick to one topic or question and it isn't too open ended. Specifically:
I get a lot of email with technical questions that would require me to download and read the documentation for libraries X, Y and Z to answer - please don't do that; instead, put the code that doesn't work (or pseudo-code that you'd like to turn into real code) in the email, and quote the prototypes for any used APIs, ideally deep-linking to their documentation just in case I do need to look at it.
Obviously, if you're planning to pay me for my help and advice as a consultant you may ignore the above. :-)
website: http://philjordan.eu/
email: phil+hn at philjordan dot eu
fedi/mastodon: @pmdj@mstdn.social https://mstdn.social/@pmdj
github: https://github.com/pmj
Fully fledged coroutines let you save and resume execution in place. The main advantage is readability of conditional/looping control flow, which tends to quickly devolve into a mess in callback style code.
Finally, wireless access points seem to be one of those things where quality varies a lot. I hated wifi for its unreliability until I bought a decent (professional/small-to-medium-business grade) AP 8 months ago. Not a single connection problem since, even with the notoriously affected Mac hardware and OSX software versions.
I don't have any data to back up or refute such a claim, but it makes sense: Europe & North America have economies of scale for internet infrastructure, including hosting, so hosting there is presumably cheaper than in SA or other African countries. Which drives the domestic demand for hosting abroad, causing that money to not be reinvested in the local infrastructure. I don't know what the solution to that is. Maybe global CDNs building (more) datacentres in Africa will bring some of that money back and have a positive impact on the local ecosystem? (Taking their hosting money abroad is presumably the rational choice for most African companies, so it's difficult to fault them for not "helping themselves")
I've visited quite a few times and yeah, your internet connections truly are painful to use even when I'm on holiday and not really using the net that much. Much worse than rural areas of Europe which typically only get 1-3Mbit/s ADSL. Some of it is the latency to faraway CDNs and EU/US-centric servers and saturated intercontinental cables, but even South African sites seem to be awfully slow, with high latency, which to me suggests overloading on the core infrastructure. Is that the case? (I know you see microwave comms towers all over the place - if those are being used as the main cross-country internet links then that could be it.)
General advice for deeply technical consulting: you need to have a lot of deep practical experience in a few specific areas and you'll generally need to hit the ground running no matter what project you're dropped into and rapidly start generating corresponding value for the client. And expect to be continuously fighting off offers of permanent employment once you start picking up work.
You'd build the suffix tree from the haystack, whereas their algorithm preprocesses the needle.
So I guess it mostly depends if you're going to be repeatedly searching different strings in the same document, or if you're searching for the same string in many different documents. Plus, space requirements might be relevant too, as a preprocessed haystack is probably bigger than a preprocessed needle.
Drawing any conclusions beyond that is frought with the peril of confounding factors…
The first's library implementation is based on boost.coroutine which as far as I'm aware uses stack-switching, so this is more of a syntax demo than a demo of the final implementation details. The fact that you can apply sizeof() to the resumable type is important for the kernel-typical pool allocators.
The second seems to have preview support in VS2015's compiler. Too bad I'm not much of a Windows programmer these days… It's not quite clear what ther memory-allocation story is from that article.
Of course the downside is it's yet another graft onto the C++ language. After ~15 years of using it, my point of view is mainly that C++'s type system and unsafe-by-default behaviour inherited from C are a mistake…
* There is little practical difference between regular threads and green threads in an OS kernel. Most OSes can't handle it if you manually mess with the stack in a kernel context anyway. (thread records are typically accessed by rounding the current stack pointer) So if you want to do synchronous-style I/O with real stacks, you'll need an OS thread for each task.
* Kernel thread stacks are fairly small; 8-16KiB are typical. The reason for this is of course that kernel stacks must use wired (non-pageable) memory, or interrupts will irrecoverably page fault. 8-16KiB is much too small for buffers of course, but also enormous compared to the actual amount of non-buffer state for most I/O tasks. In any case, you never ever want to get too close to utilising the theoretical maximum as you risk crashing the system. So for every kernel thread you create, you know you're wasting precious wired memory. Obviously, this is true for threads created from userspace too, but in the kernel, people usually don't have a choice about running your code, so you try to be as good a citizen as possible, and not fire off hundreds of threads.
* In many contexts, dynamic memory allocations are not reliable, and allocation failure must not impede progress. (I.e. I can't wait for the system to page some memory out to disk if my code is on the critical path for disk I/O.) So typically, it is desirable to pre-allocate enough memory to keep all the state required for a sequence of operations from start to finish. It's even less likely you can just spin up a new thread; so the threaded approach implies keeping a pool of threads around which is guaranteed to be big enough. A.k.a. a waste of resources.
* The chain-of-callbacks approach to I/O is even more awful in languages and environments with manually managed memory and resources.
* If I'm going to pick a fancy new language to write my drivers in, I'm still going to have to use the custom alloc/free functions for each type of kernel object (network packet, etc.) that the OS I'm writing against happens to use.
So typically, you end up either splitting your code into a bunch of callbacks, or you create a complicated explicit state machine with a giant dispatch switch() statement. In both cases all state tracked in a giant struct. Keeping track of control flow is tricky. Maintaining invariants is tricky. Making sure you don't leak (or over-free, or use-after-free) any of the resources you touch is tricky.
It'd be really, really nice if the language could help you out with this. Write it as synchronous code, and the compiler turns each location where execution can be suspended into a callback function. The locals that are used across suspension points are stored in an automatically generated struct (bonus points: unions for state which is guaranteed to not have overlapping lifetimes) which can be preallocated before firing off the "task" in question. As far as I'm aware, such a code transformation would effectively be a CPS-transform, (continuation passing style) which has at least been researched quite a bit in theory, if not so much in non-GC-language practice.
I haven't been able to invest large amounts of time into really learning Rust and applying it to my use case in earnest. It's tough without a remotely compliant standard C library around, and I've struggled a bit with trying to pick and choose bits out of Rust's 'core' library without bringing on an avalanche of dependencies. (any kernel module code is kept in wired memory, so unused code is a waste of resources in the kernel) I'm determined to overcome that though and use Rust for something other than a toy kernel module, and see if and how it improves things over C. If Rust does start supporting some kind of advanced I/O pattern that works in that sort of constrained environment, that seems like a significant competitive advantage.
Personally (as a highly employable, fairly senior software developer, so I'm unlikely to be out of a job as long as I can work) what's worse than lack of unemployment benefit is dealing with times of sickness. I suffered from Lyme disease for about 2 1/2 years until it was diagnosed properly and treated, and in addition to the reduced income due to being unable to work at times, and the extra cost of healthcare (despite the insurance it's not exactly free) in Austria, they still expect you to pre-pay taxes and pension & health insurance contributions based on your earnings 1-2 years ago. In theory you can claim some money for a few weeks if you get sick, but (a) you have to completely shut down any business activity for that time and (b) you have to be declared unable to work by a doctor. (Unlikely, considering the doctors were all telling me there was nothing wrong with me and it was "stress"…)
A basic income would at least help deal with the reduced income due to sickness & extra costs due to healthcare. The pre-payment aspect is probably peculiar to Austria and apparently frequently bankrupts profitable small businesses.
http://en.wikipedia.org/wiki/Number_sign#Usage_in_the_United...
Maybe this is true for the 95-99% most common of conditions. Doctors can be shockingly bad at diagnosing anything they don't see on a daily basis. (rare-ish conditions, unusual presentations, or anything discovered since they studied medicine)
Google search is probably very inefficient for this kind of thing, but specialised search engines based on bayesian networks or similar might get you some leads on what to test for a lot faster than going from doctor to doctor in the hope that one of them might have an idea that pans out.
Nit pick: this isn't strictly true - Spain's various islands (Balearic islands, etc.) have a different VAT rate to mainland Spain. And there are 2 towns in Austria with the same VAT rate as Germany's, not the rest of Austria's - one is an enclave in Germany, the other is only reachable by road via Germany. There are probably other weird VAT exceptions, but in any case, consumer prices must always be quoted including VAT.
Quote:
The dotless I, I ı, denotes the close back unrounded vowel sound (/ɯ/). Neither the upper nor the lower case version has a dot.
The dotted I, İ i, denotes the close front unrounded vowel sound (/i/). Both the upper and lower case versions have a dot.
End quote.
I can imagine that being a nightmare, particularly if one user uses a Turkish locale and another on the same machine uses English. And all of that complexity in the kernel? Ouch. (Or HFS+ just behaves incorrectly for Turkish file names, not sure that's really better?)