Compiling Cheap Threads

Cheap Threads includes a series of source files to be compiled and linked with your own application. Most of these source files come in two different versions -- a standard version and a version for embedded systems. One module is optional, to be included in the link only for debugging. Mix and match according to your needs.

There are three header files:

ct.h
Declares the public interface of Cheap Threads. It should be #included in any application code that calls the Cheap Threads functions.

ctpriv.h
Declares various things that are internal to the Cheap Threads software. Don't #include it in your application code unless you are monkeying with the internals (not recommended).

ctutil.h
Contains miscellaneous declarations used within the Cheap Threads software. In particular it contains prototypes for several memory management functions. This is a separate header file because nothing in it is really specific to Cheap Threads -- it's a grab-bag of things I use in a lot of different projects.
For the cttimer utility, the main() function is in: If you #include ct.h in a source file that is compiled as C++, the Cheap Threads functions will be declared as extern "C". Thus a C++ program can call these functions directly.

Standard Cheap Threads

Standard Cheap Threads is designed for a hosted implementation of Standard C. In particular it uses dynamic memory allocation (malloc and free) and it writes messages to standard error. For standard Cheap Threads, use the following combination of modules:

Embedded Cheap Threads -- No Standard Error

If you want to use dynamic memory allocation but without writing to standard error, use the following combination of source files: This combination differs from the standard combination by only a single file: it includes ecterror.c rather than cterror.c. None of the other modules accesses standard error or any other file.

When compiled with debugging turned on, the ctmemory.c source file includes calls to sprintf, one of the functions prototyped in stdio.h. If sprintf is not available to you, you'll have to either use your own version of ctmemory.c or compile it with debugging turned off.

Embedded Cheap Threads -- No Dynamic Memory Allocation

If you don't mind writing to standard error but you don't want to use dynamic memory allocation, use the following combination of modules:

Embedded Cheap Threads -- Complete

If you don't want to use standard error or dynamic memory allocation, use the following combination of modules: This list differs from the previous one by including ecterror.c rather than cterror.c.

With or Without Debugging

By default, the software includes debugging code to detect and report various kinds of internal errors. In addition, If you compile with debugging turned on, the application issues a little report on memory usage at the end, written through calls to the ct_report_error function (see the ctmemory.c module for details).

While this debugging code can be useful during development, it does incur overhead, which you presumably don't want in the finished application. Furthermore you almost certainly don't want to keep the report on memory usage.

To disable the debugging code, compile the Cheap Threads modules with the macro NDEBUG defined. Most compilers provide a way to define a macro outside of the source code, through a command line option or some other means.

If you disable debugging, you don't need to include the ctassert module in the link step. It implements a minor variation on the assert macro.


Home