| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 360 人关注过本帖
标题:大家帮我看一下这个是哪里错了
只看楼主 加入收藏
月123
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-5-4
收藏
 问题点数:0 回复次数:0 
大家帮我看一下这个是哪里错了
#include <windows.h>
#include <process.h>
#include <iostream.h>


HANDLE g_putApple;
HANDLE g_putBanana;
HANDLE g_eatApple;
HANDLE g_eatBanana;
HANDLE g_dish;
HANDLE m_hmtx;
unsigned long _beginthreadex(
                             void *security, //安全属性,NULL为默认安全属性
                             unsigned stack_size, //指定线程堆栈的大小。如果为0,则线程堆栈大小和创建它的线程的相同。一般用0
                             unsigned ( __stdcall *start_address )( void * ), //指定线程函数的地址,也就是线程调用执行的函数地址(用函数名称即可,函数名称就表示地址)
                             void *arglist,// 传递给线程的参数的指针,可以通过传入对象的指针,在线程函数中再转化为对应类的指针
                             unsigned initflag, //线程初始状态,0:立即运行;CREATE_SUSPEND:suspended(悬挂)
                             unsigned *thrdaddr );//用于记录线程ID的地址

UINT WINAPI PutAppleThread(PVOID pvParam)
{
        for(int i = 0; i < 10; i++)
       {
               WaitForSingleObject(g_dish, INFINITE);
                WaitForSingleObject(g_putApple, INFINITE);
               cout << "put apple!/n";
               SetEvent(g_eatApple);
               Sleep(5);
       }
       return 0;
}

//放香蕉
UINT WINAPI PutBananaThread(PVOID pvParam)
{
       for(int i = 0; i < 10; i++)
       {
               WaitForSingleObject(g_dish,INFINITE);
               WaitForSingleObject(g_putBanana, INFINITE);
               cout << "put banana!/n";
               SetEvent(g_eatBanana);
       }
       return 0;
}

//吃苹果
UINT WINAPI EatAppleThread(PVOID pvParam)
{
       for(int i = 0; i < 10; i++)
       {
               WaitForSingleObject(g_eatApple, INFINITE);
               cout << "eat apple!/n";
               SetEvent(g_putApple);
               SetEvent(g_dish);;
       }
       return 0;
}

//吃香蕉
UINT WINAPI EatBananaThread(PVOID pvParam)
{
       for(int i = 0; i < 10; i++)
       {
               WaitForSingleObject(g_eatBanana, INFINITE);
               cout << "eat banana!/n";
               SetEvent(g_putBanana);
               SetEvent(g_dish);
               Sleep(6);
       }
       return 0;
}


int main()
{
       g_putApple = CreateEvent(NULL, FALSE, TRUE, NULL);
       g_putBanana = CreateEvent(NULL, FALSE, TRUE, NULL);
       g_eatApple = CreateEvent(NULL, FALSE, FALSE, NULL);
       g_eatBanana = CreateEvent(NULL, FALSE, FALSE, NULL);
       g_dish = CreateEvent(NULL, FALSE, TRUE, NULL);
       m_hmtx = CreateMutex(NULL, FALSE, NULL);
       HANDLE hThread[4];
       int x;
       hThread[0] = (HANDLE)_beginthreadex(NULL, 0, PutAppleThread, (void *)&x, 0, NULL);
       hThread[1] = (HANDLE)_beginthreadex(NULL, 0, PutBananaThread, (void *)&x, 0, NULL);
       hThread[2] = (HANDLE)_beginthreadex(NULL, 0, EatAppleThread, (void *)&x, 0, NULL);
       hThread[3] = (HANDLE)_beginthreadex(NULL, 0, EatBananaThread, (void *)&x, 0, NULL);
       char ch;
       cin >> ch;
       return 0;
}
搜索更多相关主题的帖子: security include 
2014-05-04 20:24
快速回复:大家帮我看一下这个是哪里错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019415 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved