Simpel thread question(I hope:)
-
Hi everyone this is my first post so be gentle;) How do you best share data between threads? For instance if you have two arrays and the main plus another thread has to have access to them what is then the best way to create the thread? As a worker or UI thread and what about parameters and so on? Of course one could do it with global vars but I dont like globals an I will do anything to avoid them:) Any suggestions? Tnx in advance /Frank:)
-
Hi everyone this is my first post so be gentle;) How do you best share data between threads? For instance if you have two arrays and the main plus another thread has to have access to them what is then the best way to create the thread? As a worker or UI thread and what about parameters and so on? Of course one could do it with global vars but I dont like globals an I will do anything to avoid them:) Any suggestions? Tnx in advance /Frank:)
-
Hi everyone this is my first post so be gentle;) How do you best share data between threads? For instance if you have two arrays and the main plus another thread has to have access to them what is then the best way to create the thread? As a worker or UI thread and what about parameters and so on? Of course one could do it with global vars but I dont like globals an I will do anything to avoid them:) Any suggestions? Tnx in advance /Frank:)
If three threads [your primary thread + the two worker threads] are accessing the same array, then you'll be better off implementing some kind of data synchronization methods. Perhaps crictical sections would suite you well in this case. As for passing the data across threads, threads are usually passed an LPVOID parameter. You can pass a pointer to a struct that wraps all your shared arays. And this pointer can be passed to all your worker threads. But as I already said, you have to implement synchronization mechanisms else your data will get corrupted quite easily. And it won't be easy to debug as well. Regards Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Buy it, read it and admire me :-)
-
If three threads [your primary thread + the two worker threads] are accessing the same array, then you'll be better off implementing some kind of data synchronization methods. Perhaps crictical sections would suite you well in this case. As for passing the data across threads, threads are usually passed an LPVOID parameter. You can pass a pointer to a struct that wraps all your shared arays. And this pointer can be passed to all your worker threads. But as I already said, you have to implement synchronization mechanisms else your data will get corrupted quite easily. And it won't be easy to debug as well. Regards Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Buy it, read it and admire me :-)
Tnx for the quick responce both of ya! Got it then there is just one more qeustion:) So I have to use a worker thread! Because of the LPVOID param right? Can you tell me why it not possible to do that in a UI thread...why is there no LPVOID param i the UI thread? (it dont make no sence to me):confused: Am I missing something here...
-
Hi everyone this is my first post so be gentle;) How do you best share data between threads? For instance if you have two arrays and the main plus another thread has to have access to them what is then the best way to create the thread? As a worker or UI thread and what about parameters and so on? Of course one could do it with global vars but I dont like globals an I will do anything to avoid them:) Any suggestions? Tnx in advance /Frank:)
Read this article about worker threads and how you should pass data among them. Best regards, Alexandru Savescu
-
Tnx for the quick responce both of ya! Got it then there is just one more qeustion:) So I have to use a worker thread! Because of the LPVOID param right? Can you tell me why it not possible to do that in a UI thread...why is there no LPVOID param i the UI thread? (it dont make no sence to me):confused: Am I missing something here...
Got it:) Just read something from Alexpro's post:) Tnx again everyone Regards Frank