我得程序有两个死循环(因为要不停的监听两个不同的端口)
一个循环是fun1(),一个循环是fun2(),现在如果
void main()
{
fun1();
fun2();
}
这样,fun2得不到执行
所以需要线程支持,如果编写code使得fun1和fun2一起并发执行呢??在线等候!

解决方案 »

  1.   

    // 注意要设置一下多线程的链接库
    // vc6: 工程->设置->C/C++选项卡->Code Generation->Use run-time library->选择一个多线程的库.
    // vc7: 打开项目属性->C/C++ -> 代码生成 -> 选择一个多线程库#include <stdio.h>
    #include <process.h>void func1(void* p1)
    {
        while(true)
        {
            Sleep(1000);
            printf("Hello,world1\n");
        }}void func2(void* p2)
    {
        while(true)
        {
            Sleep(1000);
            printf("Hello,world2\n");
        }}void main(void) 
    {
        //启动线程执行 func1 函数
        _beginthread(func1, 0, NULL);
        //启动线程执行 func2 函数
        _beginthread(func2, 0, NULL);    //主线程永远等待下去
        Sleep(INFINITE);
      

  2.   

    提示这个错误:(libcimtd.lib(cerrinit.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int,int,char const *,int)" (??2@YAPAXIHPBDH@Z)
    libcimtd.lib(iostrini.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int,int,char const *,int)" (??2@YAPAXIHPBDH@Z)
    libcimtd.lib(streamb.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int,int,char const *,int)" (??2@YAPAXIHPBDH@Z)