www.pudn.com > first1.rar > qwe.cpp
#include#include /*******************************栈的相关操作************************************/ typedef struct M { int data; M *next; }N; N *top; HANDLE empty,full; CRITICAL_SECTION in,out; const MAX=5; //---------------入栈----------------- void push(int v) { M *t; EnterCriticalSection(&in); t= new M; t->data=v; t->next=top; top=t; LeaveCriticalSection(&in); } //----------------出栈----------------- int pop() { M *t; int v; EnterCriticalSection(&in); if(top==0) { LeaveCriticalSection(&in); return 0; } t=top; v=top->data; top=top->next; delete t; LeaveCriticalSection(&in); return v; } /*---------------消费者------------------------*/ VOID consumer(VOID) { int x,p; LONG c; for(x=0;x<10;x++) { WaitForSingleObject(full,INFINITE); Sleep(100); p=pop(); ReleaseSemaphore(empty,1,&c); EnterCriticalSection(&out); cout<<"取走第"<