C++ code to create thread to handle method
-
Hi, i need to create multithreaded environment in my Unit-testing activity. For that i need to create multiple threads which can handle methods individully. And these mthods having different parameters & return types. So as per requirement i'm trying to create thread by using CreateThread().HEre the the thread can handle mehtod like in this format "DWORD WINAPI Function( LPVOID lpParam ) " Hence my questrion is that , how can we create thread using C++ to hadle method having 'different type of method parameter' & 'method return type' as well. Please help me soon. Thanks
-
Hi, i need to create multithreaded environment in my Unit-testing activity. For that i need to create multiple threads which can handle methods individully. And these mthods having different parameters & return types. So as per requirement i'm trying to create thread by using CreateThread().HEre the the thread can handle mehtod like in this format "DWORD WINAPI Function( LPVOID lpParam ) " Hence my questrion is that , how can we create thread using C++ to hadle method having 'different type of method parameter' & 'method return type' as well. Please help me soon. Thanks
pk jain wrote:
how can we create thread using C++ to hadle method having 'different type of method parameter' & 'method return type' as well.
You don't; you create function calls to call different functions/methods. Running such calls in different threads may or may not be necessary, depending on the test environment.
Veni, vidi, abiit domum
-
Hi, i need to create multithreaded environment in my Unit-testing activity. For that i need to create multiple threads which can handle methods individully. And these mthods having different parameters & return types. So as per requirement i'm trying to create thread by using CreateThread().HEre the the thread can handle mehtod like in this format "DWORD WINAPI Function( LPVOID lpParam ) " Hence my questrion is that , how can we create thread using C++ to hadle method having 'different type of method parameter' & 'method return type' as well. Please help me soon. Thanks
I can help you in threading because your problem is simple, I would do this with a task object queue (threadpool) but do you think you need multithreading for this? You are calling different methods of objects from different threads within the same process? You can test only threadsafe methods that don't interfere with each other this way. I would rather do this with multiprocessing instead of multithreading. You start several processes each of them performing a different test. This way each process has only one main test thread but these main/test threads dont interfere with each other because they are isolated in separate processes. Sometimes multiprocessing is the winner especially when you are using a non-threadsafe library. So why do you want to use multithreading?
-
Hi, i need to create multithreaded environment in my Unit-testing activity. For that i need to create multiple threads which can handle methods individully. And these mthods having different parameters & return types. So as per requirement i'm trying to create thread by using CreateThread().HEre the the thread can handle mehtod like in this format "DWORD WINAPI Function( LPVOID lpParam ) " Hence my questrion is that , how can we create thread using C++ to hadle method having 'different type of method parameter' & 'method return type' as well. Please help me soon. Thanks
Sounds fairly basic to me, did you think of passing a context to each thread, with the context consisting of the function address to call and the parameters needed?
-
I can help you in threading because your problem is simple, I would do this with a task object queue (threadpool) but do you think you need multithreading for this? You are calling different methods of objects from different threads within the same process? You can test only threadsafe methods that don't interfere with each other this way. I would rather do this with multiprocessing instead of multithreading. You start several processes each of them performing a different test. This way each process has only one main test thread but these main/test threads dont interfere with each other because they are isolated in separate processes. Sometimes multiprocessing is the winner especially when you are using a non-threadsafe library. So why do you want to use multithreading?
And these funcitos he is tesing are going to run in seperate processes are they? How likely is that? Perhaps they do share data and use mutexes to manage this and the entire POINT of testing is to make sure they work in the SAME process? Ever thought of that?
-
And these funcitos he is tesing are going to run in seperate processes are they? How likely is that? Perhaps they do share data and use mutexes to manage this and the entire POINT of testing is to make sure they work in the SAME process? Ever thought of that?
Thanks again for your comments. Have you finished reading my post? The last question tries to find out the intentions of OP. Most of the well written modular multithreaded applications are built up from single threaded components containing the least possible locks and synchronization points between threads that work with separate instances of these single threaded modules. Since the components are usually single threaded most of the test cases are also single threaded and test the functions of a module. It's okay to create a few test cases to test the multithreaded interactions and synchronization points but this won't be the majority of the test cases. Parallelization of test cases within a single threaded component can be achieved safely only with multiprocessing. Actually I've worked on systems that were developed with lots of test cases and some of these systems were multithreaded and some of these were well designed at the same time.
-
Thanks again for your comments. Have you finished reading my post? The last question tries to find out the intentions of OP. Most of the well written modular multithreaded applications are built up from single threaded components containing the least possible locks and synchronization points between threads that work with separate instances of these single threaded modules. Since the components are usually single threaded most of the test cases are also single threaded and test the functions of a module. It's okay to create a few test cases to test the multithreaded interactions and synchronization points but this won't be the majority of the test cases. Parallelization of test cases within a single threaded component can be achieved safely only with multiprocessing. Actually I've worked on systems that were developed with lots of test cases and some of these systems were multithreaded and some of these were well designed at the same time.
Fortunately opinion and fact are two different things.
-
Fortunately opinion and fact are two different things.
If you think this then you have no clue about correct multithreading. BTW, returning to your first reply: have you read my first answer?
-
If you think this then you have no clue about correct multithreading. BTW, returning to your first reply: have you read my first answer?
Fortunately opinion and fact are two different things.
-
Fortunately opinion and fact are two different things.
If you think this then you have no clue about correct multithreading. BTW, returning to your first reply: have you read my first answer?
-
If you think this then you have no clue about correct multithreading. BTW, returning to your first reply: have you read my first answer?
I have done threadding that would make your eyes water.
-
I have done threadding that would make your eyes water.
I'm not really interested in your threading. BTW, returning to your first reply: have you read my first answer?
-
Hi, i need to create multithreaded environment in my Unit-testing activity. For that i need to create multiple threads which can handle methods individully. And these mthods having different parameters & return types. So as per requirement i'm trying to create thread by using CreateThread().HEre the the thread can handle mehtod like in this format "DWORD WINAPI Function( LPVOID lpParam ) " Hence my questrion is that , how can we create thread using C++ to hadle method having 'different type of method parameter' & 'method return type' as well. Please help me soon. Thanks
You don't need to change the param & return types of the thread function. leave them as it is. Just imagine the thread function as a platform to launch your test cases - which would be different functions. Just like the post above, I would choose to go with a data structure that takes in all the parameters required to execute the test case. Including the function pointer. If you are bothered about using function pointers you can even have a switch case block that directs the incoming structure-data to the right function using a normal function call. (it's not the best design I'd say, but it still works).
WORD WINAPI Function( LPVOID lpParam)
{
testcaseData ptcdata* = (testcaseData*) lpParam;
ptcData->Data1, data2.. etcswitch(ptcData->tcID)
{
case 0:
TestCase0(...)
case 1:}
}
And you can use the same Test case index to fill in a Results-vector or list , where it updates the result of the particular test case. The vector can be global or be part of the struct & be protected by a critical section block inside the thread.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.