-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add a basic futures example #36
Conversation
Can Tokio actually run??? This PR will have to wait for that 😂 |
It compiles at least. Might even run if I disable the time feature and count frames like this PR (it panics when creating the runtime because Instant doesn't work). But we're pretty close to getting monotonic clock working so stay tuned 😎 |
You know, a system with clear problems with threading running one of the biggest multithread frameworks, THAT is something to make |
I am not an expert in threading, so I don't know how much my question makes sense but: would it have an higher performance if we ran the task executor on the |
That makes sense. Either way the executor will yield/park the thread when it's not doing work. I'll make the change soon. |
Weird... I get a panic when I change the executor thread affinity to 1:
I checked the main thread's details (luckily ctru-rs already provides an extended thread API) and it's running on CPU 0 with priority 48. |
Ah OK, so we have to set a time limit for how much of the system core we can use before we're allowed to spawn a thread on it. Updated the PR to use the system core at up to 30% (range is 5-89 according to https://www.3dbrew.org/wiki/APT:SetApplicationCpuTimeLimit). |
rust3ds/shim-3ds#9 has been merged, and it works wonderfully. Update us on the progress 😄 |
So the tokio example gets a little farther now, after updating dependencies and calling It executes our panic handler fine (doesn't wait for input since it was not the main thread), but during unwinding it calls the Since there was a panic while already panicking, Rust aborts the process (causing an ugly ARM11 exception). This is all done with a debug build. Since the first panic was caused by a The release mode build doesn't immediately crash, but it also doesn't print any "Tick" messages. Eventually the runtime thread does panic here (condvar timeout): The main thread is still running fine, so pressing Start to exit works. |
There's some issues with the example right now. See #36 (comment)
I pushed the tokio example to a branch: https://github.com/Meziu/ctru-rs/blob/example/futures-tokio/ctru-rs/examples/futures-tokio-basic.rs |
536 core.tasks
(gdb) p core.tasks
$8 = VecDeque(size=-132873225) HMMMMMM... 🤔 |
I can't put my finger on where (because hardware watchpoints don't keep up), but at one point during the Edit: The capacity value is wrong, but the |
I'm circling around the problem. let prev = self.inner.with(|c| {
let prev = c.get();
c.set(t as *const _ as *const ());
prev
}); This is a very specific function, and it uses |
I guess our hack to get thread keys working in pthread-3ds might have a bug... |
So using a modified pthread-3ds (I'll open a PR) it now aborts here: If you move the runtime creation into the thread, it aborts here: |
In my latest iteration, it still has the weird stuff happening with VecDeque when the runtime is created outside the thread, but it acts more like the release build if you move the runtime creation into the thread. It just sits there after "Runtime started!" doing nothing. However, once you click "Start" to exit, it aborts here (when calling free in libctru): |
Opened the pthread-3ds PR: rust3ds/pthread-3ds#5 Made a few more pthread-3ds changes since the last comment. If you run this example in release mode with the runtime created on the main thread, it cleanly exits when you press Start (but doesn't print "Tick"). |
Oh yeah, and there's a rustc fix needed too: Meziu/rust-horizon#8 |
Moving discussion about Tokio to #42. Maybe we can merge this basic futures PR in the meantime? |
This example runs a basic future executor from the
futures
library.Every 60 frames (about 1 second) it prints "Tick" to the console.
The executor runs on a separate thread. Internally it yields when it has no more work to do, allowing other threads to run.
The example also implements clean shutdown by using a oneshot channel to end the future, thus ending the executor and the thread it runs on.
I was surprised that this all works as-is, without any new linker fixes needed.
I also started on a Tokio port of this example, using their timer runtime feature, but that requires rust3ds/shim-3ds#9