Archives for: June 2008, 30


Final(?) syntax for cross-thread messaging.

Permalink 17:08:46, Categories: Thread Communication  

Now that I've got something (as far as I've tested) working, I'll explain what the final system is turning out to be like.

Firstly; two reference files..*checkout*/crystal/CS/branches/soc2008/threadcomm/apps/tests/threadtest/threadtest.h*checkout*/crystal/CS/branches/soc2008/threadcomm/apps/tests/threadtest/threadtest.cpp

Start off in the header file.

Here you will see an interface; iThreadTest, and the implementation csThreadTest.

iThreadTest looks like a normal interface. Nothing new there.

You will see that csThreadTest implements ThreadedCallable. This is important, it basically allows the object instance of the class to be stored inside an event message. This message is what is sent to the thread manager and queued as a job to be executed by a thread.

In csThreadTest the functions you wish to be executed in other threads are declared with the THREADED_CALLABLE_DECX macro. You pass the class, the function name, the argument types and the argument names separately. This macro then does two things;
1) Creates a function called functionnameTC(). This is what your function will really be called.
2) Creates a function called functionname, to satisfy the implementation of the interface. This function will create a thread event based on the arguments passed to the macro and pass that thread event message to the thread manager for processing. It stores the arguments passed by copying them onto the heap and storing pointers to that data in an array.

Now look at the .cpp file.

The functions are implemented using the THREADED_CALLABLE_IMP macro. You again pass the class and function name, but this time you pass the argument type and name as a single argument, like you would declare a normal function.
This macro simply creates the function header for class::functionnameTC().

Go to the bottom where the main function is. See that the functions are called normally via the interface.

I will provide a more detailed look at how it works behind the scenes shortly.

June 2008
Mon Tue Wed Thu Fri Sat Sun
 << < Current> >>
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29




XML Feeds

What is this?

powered by