Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Task-local storage #85
Implement task-local storage for curio.
No tests yet, but everything else is there.
I added a nice example of the API in action to the tutorial -- probably that's the thing to look at first.
To highlight the two API decisions that are most likely to be controversial / I'm most uncertain about:
Sync vs async
I made the interface totally usable from synchronous code. Aside from being weird, this does force certain decisions in the implementation -- in particular it requires some hoop-jumping to set up and maintain a global (thread-local) rendesvous point for locating the current task metadata. This might have performance implications -- I haven't run benchmarks. (Specifically, doing it this way means there's a bit of extra overhead at every task switch; on the other hand, I suspect but haven't checked that it makes accessing TLS values faster than it would be if we had to trap every time.)
The rationale for this decision is that a major, probably the major use case for TLS in curio is for storing contextual metadata for logging. And logging is a thing where you kind of need to make it work, even under adverse conditions. Like if you're trying to siphon out data from stdlib
I made it so that child tasks inherit the initial values of TLS data from their parents (as a simple one-time shallow snapshot). This is very unusual among TLS implementations, but for a system like curio where tasks are small, cheap, and common, then I think it makes a lot of sense. Other alternatives include: (1) not inheriting, (2) fancier inheritance, like having children keep a pointer to their parent and if a key isn't found in a child traverse the graph looking for it (so changes in parents propagate to children but not vice-versa).
This does add some overhead to task spawning, though I suspect that it's very small in the common case (though it scales with the number of TLS keys in use).
2 times, most recently
Oct 18, 2016
Rebased on master and fixed the tests. We'll see what travis says, but they pass locally now for me. (Except for
Anyway, I think it's ready for review/merge.
Oh right, the thing about whether
The travis failure is in the doc build:
I don't think this is my fault :-)
Wondering if you saw this: https://docs.google.com/document/d/1tlQ0R6wQFGqCS5KeIw0ddoLbaSYx6aU7vyXOkv-wvlM/edit
Yeah, I was talking about this with @1st1 last night... Maybe we should
On Nov 7, 2016 3:10 AM, "Alexander Zhukov" firstname.lastname@example.org wrote: