devkitPro / newlib

fork from sourceware git://sourceware.org / newlib-cygwin.git
https://devkitpro.org
GNU General Public License v2.0
22 stars 16 forks source link

New pthread APIs in devkitARM / 3DS ? #26

Open ian-h-chamberlain opened 1 year ago

ian-h-chamberlain commented 1 year ago

Hello! I noticed with the latest devkitARM update (r60-9) that newlib was updated to 4.3.0 and there appears to be a full pthread API included as part of https://github.com/devkitPro/buildscripts/commit/cd5e224d6a14f7d32712ab10cfc08e0c6a2daea3

As far as I can tell, the syscalls used by the pthread implementation are not actually implemented anywhere, so none of the pthread_* functions actually work, which is fine - however, it does seem like on the 3DS it would be possible to implement some of the functionality using libctru calls and get a mostly-working pthread implementation.

In light of this, I had a few questions about the new changes and any future plans for them:

  1. Is there an intention to support pthreads on the 3DS?
    • If so, would the syscalls be implemented in libctru or perhaps somewhere else? Are the maintainers looking for help implementing this?
    • If not, is this a supported scenario (for users that are willing to write syscalls themselves)?
  2. Will the patch linked above eventually be delivered to the devkitARM branch of this repo? If not, is there somewhere else it lives that can be used for reference, besides just the buildscripts repo as a big diff?

Thanks in advance! I was excited to see these changes pulled down when I upgraded, but I wanted to set my expectations and see what, if any plans you all had for these APIs.

WinterMute commented 1 year ago

Shush. You weren't supposed to notice that yet :P

There is an intention to support pthreads on 3DS and, yes that support will be in libctru. We're not really looking for help with the implementation tbh but if you need something in particular we're generally willing to listen.

The devkitARM branch has now been deleted after quite a bit of work to consolidate the devkitA64 and devkitARM patchsets while updating to latest newlib snapshot in order to ease future maintenance and work towards feature parity. These changes now live at https://github.com/devkitPro/newlib/tree/devkitPro

ian-h-chamberlain commented 1 year ago

There is an intention to support pthreads on 3DS and, yes that support will be in libctru.

Awesome, that's great news to hear, thank you!

but if you need something in particular we're generally willing to listen.

I think the only thing that came to mind when I first started looking at the implementation was that it would be nice to have some way to set CPU affinity / priority at thread creation time. It looks like __syscall_thread_create doesn't have access to everything in the pthread_attr_t* used to create the thread (just stacksize and stackaddr).

It would be great if we were able to use APIs like phread_attr_setschedparam and pthread_attr_setaffinity_np to change thread properties before creating a thread (particularly CPU affinity, since it seems setting after thread creation hasn't been supported for some time).

Clearly this is still under active development so I'll try not to get ahead of myself, but thank you for your work and I look forward to seeing further development on this front! :rocket: