-
Notifications
You must be signed in to change notification settings - Fork 795
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
Why ThreadX entry function use ULONG
as entry input instead of a void *
?
#413
Comments
It could be because of certification reasons, to avoid using You can therefore use the casting, or pass the index, and retrieve the parameter via other API function passing index to it. |
This explanation doesn't convince me. |
In fact you are right. Then it might be "legacy". There are other details to challenge too, such as missing const keyword for thread name. Ive asked for an update in the past, they claimed we need to keep no const for legacy. Clearly unjustified reason as ut would not break anything. |
This raises another question: How do I pass one or more parameters (more complex than a |
You should cast your pointer to ULONG and retrieve it back. This you can do. |
As far as I know in C there is no guarantee that an |
As stated above, in general you are right, but if you system is |
I think the "32-bit system" requirement is not enough to ensure safe conversion from I'm writing a code (portable across different platforms) where I need to pass multiple parameters to a thread during its creation, I guess I'm not the first to encounter this problem, what mechanism has ThreadX implemented to be able to do this? |
Then the best proposal is to start the thread passing the data index and retrieving the data by: void* get_thread_data(ULONG index) {
return data_pointers[index];
}
void
thread_func(ULONG value) {
void* data = get_thread_data(value);
} |
I guess (as you already mentioned in your first answer) this is the best solution, although I don't like the idea of a global |
ULONG
as entry input instead of a void*?
ULONG
as entry input instead of a void*?ULONG
as entry input instead of a void *
?
Hi we run across this often. The purpose of the formal parameter is to pass either a start code scalar integer, or alternatively an opaque pointer to a context structure. By convention ULONG is universal for 32 bit architectures and defined to be uint32_t, which also happens to be the size of a pointer. However on 64 bit machines the pointer will typically be allocated 8 bytes. For future updates it may be better to use stdint.h uintptr_t to pass an opaque pointer https://cplusplus.com/reference/cstdint/ |
IMHO It should be void* and nothing else. Everything else is a workaround of a bad design. |
@cypherbridge As So the condition that must be satisfied in order to pass pointers is: In any case, why |
It think there seems to be consensus that changing it to a portable pointer type makes sense. Maybe @parmi93 could create a respective PR? In the mean time the opaque pointer cast can be considered a workaround for 32-bit architectures. The segmented 48-bit pointer case is hypothetical as to my knowledge ThreadX presently does not support such an architecture. |
C99 defines uintptr_t is defined in such a way to transparently convert between a pointer and and scalar. |
I think the rationale is well explained by @parmi93 and I agree with the need for a mechanism to pass arbitrary context data to the thread in creation. This is common practise with all OS I have come across being it RTOSes or Linux or Windows and typically accomplished by passing a user defined pointer to the new thread. We are using this in our application as well and so far using the ULONG entry_input argument casted into from a pointer to a struct., but it would be better to change that to a |
And I agree this would be a breaking change, but sometimes in order to move forward you have to leave lagacy stuff behind. A ULONG was find when the world embraced 32-bit 20 years ago but now we have micros entering the 64-bit realm. |
Looks like tx_timer_create have a similar mechanism using a ULONG for its expiration_function id paramater and for its expiration_input.
I feel like these could be VOID * also.
Alex Grutter
Engineer
Future Designs, Inc.
996 A Cleaner Way SW Huntsville, AL 35805
Mobile: (256) 609-8767
Phone: (256) 883-1240 ext. 34
Fax: (256) 883-1241
From: cypherbridge ***@***.***>
Sent: Thursday, October 3, 2024 7:05 PM
To: eclipse-threadx/threadx ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [eclipse-threadx/threadx] Why ThreadX entry function use `ULONG` as entry input instead of a `void *`? (Issue #413)
C99 defines uintptr_t is defined in such a way to transparently convert between a pointer and and scalar.
With the benefit of cross-platform code, 32bit 64 bit, whatever.
Its true that in some projects ThreadX is used in C89 compiler which predates uintptr_t so for that reason
void* is a better choice and additionally similar to FreeRTOS xTaskCreate()
It seems the only use case we are talking about is tx_thread_create(), is there anything else affected by this?
Do keep in mind that whatever we come up with has the potential for broad impact to the installed code base, documentation, and so on. So what is the the rationale to do it?
—
Reply to this email directly, view it on GitHub<#413 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AIBCG7ON34AOSKYZCHQZUKLZZXLRBAVCNFSM6AAAAABPF5CULWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJSGUZTKOBRGU>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.******@***.***>>
|
I don't understand why ThreadX needs to bother allowing the user to convert a pointer to a scalar? If
I would also like to add that the In any case I wasn't suggesting changing I would recommend adding a new |
Or a threadx options where user can define the parameter type. |
This solution is even better, because it would not change the size of the program (binary) for those who want to continue using |
I like the option of being able to configure the type of Having a second |
A pointer points to an address of memory. The address of the memory is also a ULONG-compatible type. |
Not the case. |
This is not true, please read the entire discussion above. |
Documentation
If I need to pass more than one parameter to the
entry_function
I must necessarily use avoid *
, hence my question, why ThreadX uses aULONG
instead of avoid *
like FreeRTOS does?The text was updated successfully, but these errors were encountered: