I have a design question I am hoping you can help me resolve. I have an application with a GUI thread and several "worker threads" in a pool, to which I pass jobs by adding jobs to a queue (my architecture closes resembles the complete example here: http://wiki.wxwidgets.org/Inter-Thread_ ... munication).
I would like to be able to pass different kinds of jobs to the threads, but each type of job requires different inputs, so when I created my tJOB class, I took the quick and dirty approach, and I can create the job with as many or as few arguments as I need. For example, my tJOB constructor looks like this:
Code: Select all
tJOB::tJOB(tCOMMANDS cmd, int forJobType1, bool forJobType2, wxString forJobType3);
Code: Select all
tJOB *newJob = new derivedJOB();
m_pQueue->AddJob(*newJob);
My next thought was to use a union, but I'm being foiled by the 'union members may not have non-trivial constructors' as some of the data objects that I'm passing to the thread have non-trivial constructors.
Hopefully this isn't too confusing - I think it illustrates what I was hoping to accomplish. What do you do to solve this problem? The two best options I can come up with are using separate queues for each different type of job (which I don't particularly want to do), or have a tJOB constructor that takes enough arguments to accommodate all of my job types, and stores all of the data in its own members, even if some of it is garbage, and won't be used for that particular job.
Any advice is welcome!
Thanks,
Kerry