I am trying to use multithreading to allow two functions to run in parallel within a DLL, But my application remains crashed, apparently due to some bad processing conflict management; Here are the details: With the main logic flow, I need to call the same function (DoGatrainAndRun) from a certain point, give a different value for one parameter, give two runs, then go back to the main logic flow, and Use two (separate) sets of two values from 2 calls.
(This is in the main header file):
typedef struct {int PredictorId; Int output type; Int Delta; Intel scale; Int debug; File * logfile; Intel Cables; Double CBC Double * Hewel; Int pedicelan; Double *** forecasts; } T;
(this main argument is in the flow):
hRunMutex = CreateMutex (NULL) , FALSE, NULL); Arg- & gt; OutputType = FH; Handle = (handle) _biginthread (DoGatrainAndRun, 32768, (zero *) arg); Arg- & gt; OutputType = FL; Handle = (handle) _biginthread (DoGatrainAndRun, 32768, (zero *) arg); While {} do (hRunMutex! = 0); CloseHandle (hRunMutex);
(This is at the end of DoGaTrainAndRun):
Free (Args); Release Mutx (HRnmutx);
I am very new to multi-threading, and I can not find this ...
First of all, you are passing the same structure in both threads, but changing the output type
, post-text "itemprop =" text ">
value. If you see the first thread fl
and never see the value FH
the reason for this is how the thread is determined. This is your first thread It is valid for the user and can then be suspended. Then, after setting your main thread output type
to FL
, the second thread is created. This thread starts and before One even starts again. However, the first one is now output type
as FL
.
Next, both threads use the same structure But one of these is releasing the memory. If the other thread is still released after its release So is using you will get undefined behavior thread is still using it will probably result in an accident.
You are trying to wait for the threads to exit, is wrong. You do not need a Mute X and you definitely do not need to spinning it, use the test bus for zero:
handle handle [2]; Handle [0] = (handle) _biginthread (...); Handles [1] = (Handle) _biginthread (...); Waiting Multilube Objects (2, Handle, True, EnFinance);
This will prevent your main thread from spinning around ruining CPU cycles. When waiting, you will know that both threads have ended.
By putting it together you should do something like this:
handle handle [2]; T * arg1 = malloc (sizef (t)); Arg1-> Output Type = FH Handle [0] = (Handle) _Biginthread (DoGatrainAndRun, 32768, (Zero *) arg1); T * arg2 = mauloq (size (t)); Arg2-> Output Type = FL Handle [1] = (Handle) _Biginthread (DoGatrainAndRun, 32768, (Zero *) arg2); Waiting Multilube Objects (2, Handle, True, EnFinance); Free (ARG1); Free (arg2)
and DoGatrainAndRun
.
Comments
Post a Comment