[wx-dev] wxThread, thread local storage and wxLog
Armel Asselin
asselin.armel at wanadoo.fr
Fri Aug 11 01:00:26 PDT 2006
> On Thu, 10 Aug 2006 18:44:11 +0200 Armel Asselin
> <asselin.armel at wanadoo.fr> wrote:
>
> AA> ok for all of that, so let's summarize:
> AA> for TLS stuff?
> AA> - we should do a class named wxTheadLocalStorage or (wxTLS?)
>
> I prefer the POSIX-inspired wxThreadSpecificData.
>
> AA> - we must choose an allocation strategy
>
> wxThreadSpecificData uses a single slot per object (so you may not create
> more than a few dozens or, at best, few hundreds, of them). However *all*
> thread-specific data used by wx itself (including current wxThread object,
> the log target for this thread and I don't know what else) must use a
> single wxThreadSpecificData which would contain a pointer to wxThreadData
> (this class is internal to the library).
>
> AA> - whatever the chosen storage, we can make a wxTLSSlot class which
> could
> AA> allocate/free the TLS entry in constructor/destructor at module
> AA> loading/unloading time (ie. process or dyn lib), and have a member
> set/get +
> AA> a deletion function if wanted. a simple template wxTLSSingleton<T>
> could
> AA> encapsulate that for the user.
>
> This is the same class as above. You just put auto_ptr<T> into it.
>
> AA> for wxLog stuff:
> AA> - a (private or protected) object: wxLog::PerThreadData should be
> stored
> AA> with wxTLSSlot. It would store all the data which may create problems
> if
> AA> shared among threads, currently the ActiveTarget creates problems.
> AA> - SetActiveLogTargetPerThread( ) should use a wxTLSSlot. Used by
> wxLogNull
> AA> (avoiding wxLog::ms_doLog global).
>
> This should go into wxThreadData.
this wxThreadData structure which from your description would be something
like:
srtuct wxThreadData {
wxThread *wxThread_This;
bool wxLog_ActiveTarget;
};
this is the kind of structure that i generally avoid, because:
- it will mix data from heterogenous classes
- we will need to include the header in many different .cpp (one change,
many recompile)
- if variables are added/removed by different developpers, which is probable
because of its "unique" nature, merges will be a nightmare
(this is another reason for the single system TLS entry + wx array)
however i'll probably just do that and then won't put my hand in wx code for
months, so if you prefer this organization let's go, whatever the case, if
you/we realize later that using this structure is a really a problem, it is
always possible to then use a the other approach.
another note, the 'single system TLS entry + wx array' approach could would
be easy to implement on all the couple systems+compiler which have a
__threading or __declspec(thread) keyword.
i start coding the basic into a wx/tls.h header + private headers
wx/msw/tls.h and wx/unix/tls.h, is it OK?
for mac, I do not know how it works, is it phtread based? (as it is Unix
based now its probable)
Armel
More information about the wx-dev
mailing list