当
C runtime 函数库于20世纪70年代产生出来时,PC 的内存容量还很小,多任务是个新奇的观念,更别提什么多线程了。因此以当时产品为基础所演化的 C runtime 函数库在
多线程(multithreaded)的表现上有严重问题,无法被多线程程序使用。
利用各种同步机制(synchronous mechanism)如 critical section、mutex、semaphore、event,可以重新开发一套支持多线程的 runtime 函数库。问题时,加上这样的能力,可能导致程序代码大小和执行效率都遭受不良波及——即使你只激活了一个线程。
Visual C++ 的折衷方案是提供两种版本的 C runtime 函数库。一种版本的给单线程程序使用,一种版本给多线程程序使用。多线程版本的重大改变是,第一,变量如 errno 者现在变成每个线程各拥有一个。第二,多线程版中的数据结构以同步机制加以保护。
Visual C++ 一共有六个 C runtime 函数库产品供你选择:
1、
Single-Threaded (static) libc.lib 898,826
2、
Multithreaded (static) libcmt.lib 951,142
3、
Multithreaded DLL msvcrt.lib 5,510,000
4、
Debug Single-Threaded (static) libcd.lib 2,374,542
5、
Debug Multithread (static) libcmtd.lib 2,949,190
6、
Debug Multithreaded DLL msvcrtd.lib 803,418
Visual C++ 编译器提供下列选项,让我们决定使用哪一个 C runtime 函数库:
1、
/ML Single-Threaded (static)
2、
/MT Multithreaded (static)
3、
/MD Multithreaded DLL (dynamic import library)
4、
/MLd Debug Single-Threaded (static)
5、
/MTd Debug Multithreaded (static)
6、
/MDd Debug Multithreaded DLL (dynamic import library)