JTCTHREAD Sample
JTC supports new old iostream library, using new old flow methods to define Have_iostream through macro.
JTC supports the namespace, defined by using a Have_STD_IOSTREAM macro.
Note:
These macro definitions are very common in GNU, GPL code, usually through the AutoConf mechanism
It is a platform-related configuration config.h header file that defines the supported platforms and compilers in the file.
#ifdef Have_ioStream
# Include
#ELSE
# Include
#ENDIF
#ifdef Have_STD_IOSTREAM
Using namespace std;
#ENDIF
Define the thread class, mainly implementing the RUN function of the JTCRunnable abstract class
Class Clock: Public JTRNABLE
{
Void Run ()
{
Printf ("Hello, JTC THREAD.");
}
}
Use thread class instance
INT main (int Argc, char ** argv)
{
Try
{
// Before using the JTC thread, you must initialize the thread library.
JTCinitialize Bootjtc (Argc, Argv);
/ / Generate a thread class instance, especially paying, should not directly use the object declaration,
// is used in conjunction with the New and JTCHandlet templates, and JTCHandlet is managed.
// Thread example generated by the New. In this way, it will produce in Win32.
// crash, why? This involves another problem.
JTCHANDLET
// Start thread
C -> Start ();
// Main program sleep
JTCTHREAD :: Sleep (1000 * 5);
// thread stop
C -> stop ();
// below is JTC abnormal processing
} catch (const jtcexception & e) {
CERR << "JTCEXCEPTION: << E.GetMessage () << endl;
}
Return 0;
}
Note:
Quite a simple thread program, just pay attention to some things during the use, the JTC thread is
Very easy to use. If you need further understanding of JTC, you can see what I look at the JTC code.
Write the right to learn the writes.