-
-
Notifications
You must be signed in to change notification settings - Fork 849
core:thread get_name/set_name #5464
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I’m not sure about this API call. per documentation it might be ^PWSTR but that doesn’t make sense cause it’s a pointer to a pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a pointer to a pointer because it's writing the buffer's pointer at the one we give it. It doesn't copy the whole buffer back to you. It just returns a pointer to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to still manually allocate a buffer for the entire string or we’ll be fine just using the pointer?
edit:I forgot that we’d have to allocate for the returned string anyway, but I’m still curious how it will manage the buffer after the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a pointer to a pointer because it's writing the buffer's pointer at the one we give it. It doesn't copy the whole buffer back to you. It just returns a pointer to it.
laytan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With macos not supporting setting the name of another thread, should we just not support it anywhere, so we have a consistent API?
I'm wondering whether adding a possibility to Similar to how Java does it with |
Good idea! |
Yeah, I was also hesitant about this but It feels weird to shun others capability just to make this one feels consistent. I think the solution to have all the OS refer to the calling thread is pretty neat though. but, I would gladly comply if it’s somehow idiomatic.
I also think this is a good idea. but, I’m not sure about not adding thread.set_name at all though. even though I don’t personally use it. @GloriousPtr thoughts? |
Co-authored-by: Laytan <[email protected]>
Co-authored-by: Laytan <[email protected]>
Co-authored-by: Laytan <[email protected]>
Co-authored-by: Laytan <[email protected]>
Co-authored-by: Laytan <[email protected]>
|
I would still get rid of the set_name, and instead move this name to thread.create, where something like __unix_thread_entry_proc and similar would set the name on the running thread itself |
|
@laytan I just looked at how Zig does it, and it simply returns an https://ziglang.org/documentation/master/std/#std.Thread.setName Seems like a reasonable tradeoff right?, additionally still keep the idea of an initial thread name param. |
|
If we’re going down the thread.create_with_name* route, I think we don’t need to have a get_name. we have to make a struct field (thread.Thread) for the name to make it callable from inside the thread, so if we want to retrieve the name, we can just t.name or something like that. |
I disagree, I don't see a reason to add this field to a Thread, the kernel already represents the single point of truth for this value. My idea was to do something like this: thread.create :: proc(procedure: Thread_Proc, priority: Thread_Priority = Thread_Priority.Normal, name: Maybe(string) = nil) -> ^Thread(Similarly for all those other variants) |
yeah, I suppose you’re right on not getting rid of get_thread. But we do need to add a field in thread.Thread in order to pass it inside __unix_thread_entry_proc and __windows_thread_entry_proc though… right? |
Looks like it, can't use context._internal here because the windows thread entry proc may not be called immediately |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the note for all procedures that take in a name for creating a thread/setting the thread name that name parameter is truncated to 16 characters on unix and 64 characters on windows.
| foreign import pthread "system:pthread" | ||
|
|
||
| foreign pthread { | ||
| pthread_getname_np :: proc(thread: posix.pthread_t, name: [^]u8, len: c.size_t) -> posix.Errno --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating 5 files for each of the platforms, I think you should just add these bindings to sys/posix/pthread.odin. They don't seem to be platform specific and there's no point in duplicating the files when you can bind these procedures in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
it is actually platform specific, the input arguments for the foreign functions are not the same. I actually wanted to put it in the same file but I’m not sure if we can do something like a
WHEN ODIN_OS == .smthinside a foreign block though, so I went with this. -
These functions are not listed in the POSIX standard. I’ve been informed that the core:sys/posix adheres to it very strictly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, then it's good. I'm not familiar with posix much, I assumed it would have been part of pthreads
Improve code description Co-authored-by: Sunagatov Denis <[email protected]>
|
Looks fine to me, is it tested |
peperronii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed and tested on macos_arm using thread.create and thread.get_name.
feature request #5314
tested on arm_darwin