J
Jakob Bieling
Thank all of you for all your answers, I really
appreciate it. But there's one very imporatant
thing that I might have been a little vague about,
and that is the importance of not having to
recompile the application because of a library
change. Therefore #ifdef won't do.
But will you not have to recompile anyway, since you cannot use the
Linux executable on a Windows system anyway?
Suppose you sell your application to someone and
this guy in turn buys a plugin to it from a third
party vendor, where this plugin only supports
"strangeThread" but not the apps default pthread.
Then it would be neat to just send him a new
strangeThread.so or .dll to put in a specific
directory and suddenly it works.
Well, think about it. That plugin is written after you ceated your app,
so who would ever create a plugin that does not work with the app? Sure, you
do restrict plugin writers to use a specific lib, but that is life
It's feasible with the design patterns 'abstract
factory' or 'bridge', but both of them result in
an overhead with pointer referencing and memory
allocation. I just wanted that C++ could do it
anyway, but the only solution I can see right now
is this solution
As I mentioned in another post, you just create an interface and let the
libraries contain a derived class from that interface and let it do all the
implementation specific stuff. Then you have the dynamic lib export two
functions: create_thread and destroy_thread. In the former you allocate the
derived class with new and return the pointer, in the latter you destroy it
again. The overhead of allocating from the heap will surely be neglectable,
because it is rather unlikely that you will create hundrets of threads ..
hth