Bonita,
>> You did not yet explain what "this storage" is, ...
>
> Ok, you don't know it.
Not at the moment you mentioned it, no. IOW, the order in which you
explained yourself left a bit to be desired.
>> Shouldn't you already know that when you create that DLL ?
>> IOW, a constant set in the DLLs sourcecode should cover it.
>
> DLLs don't support TLS.
Whut? You have even included code showing they do.
>> If your program comes across the Tls storage initialisation code multiple
>> times you're probably doing something wrong. ...
>
> This doesn't happen since the operating system does DLL_THREAD
> _ATTACH calls only once for each thread.
In that case, why did you mention the need for a boolean ?
>> But if you have that problem, why not use the variable that stores the
>> index
>> as the "boolean" itself.
>
> Because TLS does need much more information per thread than s single
> boolean.
Read what you quoted again. Notice both that I said "why not *USE*" as well
as me quoting the "boolean" word, giving an indication that its not actually
a boolean but something else. But read on.
>> Just initialize it with the TLS_OUT_OF_INDEXES value.
>
> *facpalm*
> Are you trolling ?
Yes, that must be it. On the other hand, you just might not have
understood what I tried to offer you :
Create the (global) __tls_index variable initialized with the value
TLS_OUT_OF_INDEXES. Than use the following:
pseudo-code:
- - - - -
if __tls_index == TLS_OUT_OF_INDEXES {
__tls_index =TlsAlloc()
if __tls_index == TLS_OUT_OF_INDEXES {
Houston, we have a problem and need to abort.
}
- - - - -
At this point you have either aborted, or the __tls_index variable contains
a value different from TLS_OUT_OF_INDEXES, meaning that the next time around
the Tls slot intialisation (and its result checking) will be skipped.
>> As mentioned in the above, if you are writing the DLLs thread you should
>> be able to know how much thread-global storage you need for it.
>
> The DLL itself determines how much thread-local storage has to
> be allocated, it's the same for all targets.
You're confusing me : What is the below than all about ? :
[quote]
as well as a variable in read-only memory which gives the amount of storage
which needs to be allocated with the total amount of storage needed for a
thread.
[/quote]
Either you do /not/ know how much you need to allocate and it needs to be
gotten from where you stored it somewhere in your DLL (but where than do you
get the number from you have stored there ?), or you /do/ know, and no such
storage is needed. Not both.
Remark :
My previous message as well as the current one have been written in an
attempt to give you some hints and further possibly worth-to-know info.
If you think you should be nasty about it I think I will just leave you to
your own devices.
Though congrats for figuring out how to use Tls in DLLs (even though that is
what it was ment for in the first place). I know from experience how
difficult the "how the h*ll does that work ?" sometimes is.
Regards,
Rudy Wieser