急求高手回答。。。。。用VC编程

faithsunsun 2008-11-10 12:26:38
某工厂有两个生产车间和一个装配车间,两个生产车间分别生产A、B两种零件,装配车间的任务是把A、B两种零件组装成产品。两个生产车间每生产一个零件后都要分别把它们送到装配车间的货架F1、F2上,F1存放零件A,F2存放零件B,F1和F2的容量均为可以存放10个零件。装配工人每次从货架上取一个A零件和一个B零件然后组装成产品。请用多线程并发进行正确的管理
...全文
151 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fdhdf 2012-03-21
  • 打赏
  • 举报
回复
能不能发一份给我,435617138@qq.com
faithsunsun 2008-11-11
  • 打赏
  • 举报
回复
谢谢大家的回答,我自己也写了个,不过有些小问题,还在修改中。谢谢大家的回答啊
naiveC 2008-11-10
  • 打赏
  • 举报
回复
正确的管理?
要代码?
bobob 2008-11-10
  • 打赏
  • 举报
回复
标题改成“急求作业”合适
yayafu 2008-11-10
  • 打赏
  • 举报
回复
好了
cnzdgs 2008-11-10
  • 打赏
  • 举报
回复
货架F1、F2各搭配一个锁即可。
TearyWang 2008-11-10
  • 打赏
  • 举报
回复
应该是操作系统的作业吧!考的好像是进行互斥问题中生产者消费者这个部分。
  • 打赏
  • 举报
回复
2个队列?
路人乙2019 2008-11-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 oyzdz1988 的回复:]
呵呵,闲着没事,简单写了个你看行么,

C/C++ code
#include <iostream>
#include <cstdio>
#include <process.h>
#include <windows.h>
using namespace std;

HANDLE hMutex1, hMutex2;
class Product
{
public:
int F1 ;
int F2 ;
Product()
{
F1 = 0;
F2 = 0;
hMutex1 = CreateMutex(NULL,FALSE,NULL);
hMutex2 = CreateM…
[/Quote]兄弟很敬业。
这个是很基础的东西。你还可以用关键代码段,看得懂些。
oyzdz1988 2008-11-10
  • 打赏
  • 举报
回复
呵呵,闲着没事,简单写了个你看行么,

#include <iostream>
#include <cstdio>
#include <process.h>
#include <windows.h>
using namespace std;

HANDLE hMutex1, hMutex2;
class Product
{
public:
int F1 ;
int F2 ;
Product()
{
F1 = 0;
F2 = 0;
hMutex1 = CreateMutex(NULL,FALSE,NULL);
hMutex2 = CreateMutex(NULL,FALSE,NULL); //互斥量生成
start_Threads();
}

friend void produce_A(void* p);

friend void produce_B(void* p);

friend void merge_AB(void* p);

void start_Threads()
{
while(1)
{
_beginthread(produce_A, 0, (void*)this);
_beginthread(produce_B, 0, (void*)this);
_beginthread(merge_AB, 0, (void*)this);
Sleep(1000);
}

}
};

void produce_A(void* p)
{
Product* product = (Product*)p;
//等待获得互斥对象的所有权
WaitForSingleObject(hMutex1,INFINITE);
if(product->F1 < 10)
{
product->F1++;
printf("Part A been produced, now total is %d .\n",product->F1);
}
Sleep(1000);
//释放互斥对象的句柄
ReleaseMutex(hMutex1);

}

void produce_B(void* p)
{
Product* product = (Product*)p;
//等待获得互斥对象的所有权
WaitForSingleObject(hMutex2,INFINITE);
if(product->F2 < 10)
{
product->F2++;
printf("Part B been produced, now total is %d .\n",product->F2);
}
Sleep(2000);
//释放互斥对象的句柄
ReleaseMutex(hMutex2);

}

void merge_AB(void* p)
{
Product* product = (Product*)p;
WaitForSingleObject(hMutex1,INFINITE);
WaitForSingleObject(hMutex2,INFINITE);
if(product->F1 > 0 && product->F2 > 0)
{
product->F1--;
product->F2--;
puts("a Finished Product!\n");
}
Sleep(3000);
ReleaseMutex(hMutex2);
ReleaseMutex(hMutex1);

}

int main()
{
Product p;
system("pause");
return 0;
}

ilovedrv 2008-11-10
  • 打赏
  • 举报
回复
这个不难的啊,建议还是自己动手写写代码吧

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧