![]() |
【转帖】multithreaded achievement of sw api
multithreaded achievement of sw api
hi! i have a quad core computer. if i use the conventional sw connetion method, only 1 processor working. i would like to push the advantage of the four processors, and i like to cut my job for 4 thread, after the threads run in paralel...) i like create more instance of sw api, afterwards these the instance to separate threads to order. it is possible? (i use c++ and com) hresult hcomres = coinitializeex(null, coinit_multithreaded); if (hcomres != s_ok) { cout << "error under initializing com. exiting..." << endl; return 1; } ccomptr swapp; ccomptr swapp2; hresult hres1 = swapp.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server); hresult hres2 = swapp2.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server); this code is bad, bacause the pointers swapp and swapp2 is equal. thanks! regards: zszs. you need to start a new instance of sw, get its pid (process id), then call i say thank you for your answer, i will try it. did i understand well? the 1. initialize the com port ( coinitializeex(null, coinit_multithreaded) ) , the 2. i create 4 threads, the 3. in all threads a sw i create an object instance ( swapp.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server) ) , the 4. i call for all threads the setthreadaffinitymask() function. regards: zszs. thats basically it yes. it is a theory i have thought of and presume will work but have not tested anything so let me know your results. is disappearing in that manner works! i opened it only temporarily and i closed it two different documentumot on the two threads. my sample-code: -------------------- #include "sldworks_api_session.h" #include "thread.h" #include "util.h" using namespace std; struct parthread { ccomptr{isldworks} swapp; string docname; }; std::vector{parthread} vecthreadparams; dword winapi workproc(lpvoid pparam); int _tmain(int argc, _tchar* argv[]) { hresult hres = coinitializeex(null, coinit_multithreaded); if (hres != s_ok) { cout << "error under initializing com. exiting..." << endl; return 1; } int par1 = 0, par2 = 1; parthread pt1, pt2; pt1.docname = "d:\\x\\labe00_01001\\labe00_01001.sldasm"; pt2.docname = "d:\\x\\labj00_01001\\labj00_01001.sldasm"; vecthreadparams.push_back(pt1); vecthreadparams.push_back(pt2); thread* thr1 = new thread(workproc, &par1); thread* thr2 = new thread(workproc, &par2); thr1->resume(); thr2->resume(); while( (thr1->getexitcode() == still_active) || (thr2->getexitcode() == still_active) ); delete thr1; delete thr2; for(int i=0; i<=vecthreadparams.size()-1; i++) vecthreadparams.swapp = null; couninitialize(); return 0; } dword winapi workproc(lpvoid pparam) { int* paridx = (int*) pparam; hresult hres = vecthreadparams[*paridx].swapp.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server); isldworks* papp = vecthreadparams[*paridx].swapp; string docname = vecthreadparams[*paridx].docname; ccomptr{imodeldoc2} swdoc; string outmsg; long er, wa; hres = papp->opendoc6(util::str2bstr(docname), swdocassembly, swopendocoptions_silent, _bstr_t(""), &er, &wa, &swdoc); if( (hres == s_ok) && (swdoc) ) { outmsg = "thread:" + util::i2s(*paridx) + " opened."; hres = papp->closedoc(util::str2bstr(docname)); } else outmsg = "thread:" + util::i2s(*paridx) + " error."; cout << outmsg << endl; swdoc = null; return 0; } ----------------- comments: 1. the system took the words written between the pointed brackets out unfortunately! (pointed brackets template classes we are useful the c in c++) i changed the {} pairs instead of pointed brackets. 2. the "util" and "thread" classes they are my classes. 3. i don't use the setthreadaffinitymask() function. the system put the threads difference processor in default. i say thank you for your idea! regards: zszs. edited: 10/29/2008 at 04:14 am by zsolt zsupán glad it worked, others should find this very useful for processor intensive tasks where time is critical |
所有的时间均为北京时间。 现在的时间是 10:48 AM. |