´ó¹¤18´º¡¶²Ù×÷ϵͳ¡·´ó×÷ÒµÌâÄ¿¼°ÒªÇó´ð°¸

}

}

}

std::cout<

/*----------------------°ÑÐÂÉú²úµÄ²úÆ··ÅÈ뻺³åÇø½áÊø------------------------*/

/*----------------------------------------------------------*/

void Consume()//Ïû·ÑÒ»¸ö²úÆ· { }

/*----------------------------------------------------------*/

/*-----------------------´Ó»º³åÇøÖÐÈ¡³öÒ»¸ö²úÆ·¿ªÊ¼-------------------------*/

//´Ó»º³åÇøÖÐÈ¡³öÒ»¸ö²úÆ· void Take() {

std::cout<

std::cerr<<\´Ó»º³åÇøÈ¡³öÒ»¸ö²úÆ·\ConsumeID=g_buffer[out]; out=(out+1)%SIZE_OF_BUFFER; std::cerr<

Ïû

·Ñ

Ò»

¸ö

²ú

Æ·

½á

Êø

std::cout<

std::cerr<<\Ïû·ÑÒ»¸ö²úÆ·: \std::cout<

Ïû

·Ñ

Ò»

¸ö

²ú

Æ·

¿ª

ʼ

}

std::cout<<\»º³åÇø ²úÆ· Éú²úÕß/Ïû·ÑÕß\//È¡³öÒ»¸ö²úÆ·ºó£¬Êä³ö»º³åÇøµ±Ç°µÄ״̬ for(int i=0;i

//Êä³ö»º³åÇøϱê if(i<10)

std::cout<

else

std::cout<

if(i==in) { }

if(i==out) { }

std::cout<

if(g_buffer[i]<10)

std::cout<<\if(g_buffer[i]<10)

std::cout<<\

else

std::cout<<\

std::cout<<\Éú²úÕß\Êä³öÉú²úÕßµÄÖ¸ÕëλÖÃ

else

std::cout<<\

std::cout<<\Ïû·ÑÕß\Êä³öÏû·ÑÕßµÄÖ¸ÕëλÖÃ

/*-----------------------´Ó»º³åÇøÖÐÈ¡³öÒ»¸ö²úÆ·½áÊø

-------------------------*/

/*-----------------------------Éú

²ú

Õß

Ïß

³Ì

-------------------------------*/

//Éú²úÕßÏß³Ì

DWORD WINAPI Producer(LPVOID lpPara) { while(g_continue) { //×ÊÔ´ÐźÅÁ¿µÄP²Ù×÷

WaitForSingleObject(g_hFullSemaphore,INFINITE);

//»¥³âÐźÅÁ¿µÄP²Ù×÷ WaitForSingleObject(g_hMutex,INFINITE); //Éú²úÒ»¸ö²úÆ· Produce();

//°ÑÐÂÉú²úµÄ²úÆ··ÅÈ뻺³åÇø Append(); Sleep(2000); //»¥³âÐźÅÁ¿µÄV²Ù×÷ ReleaseMutex(g_hMutex); //×ÊÔ´ÐźÅÁ¿µÄV²Ù×÷

ReleaseSemaphore(g_hEmptySemaphore,1,NULL);

} return 0;

}

/*-----------------------------Éú

²ú

Õß

Ïß

³Ì

-------------------------------*/

/*-----------------------------Ïû

·Ñ

Õß

Ïß

³Ì

¿ª

ʼ

½á

Êø

¿ª

ʼ

-------------------------------*/

//Ïû·ÑÕßÏß³Ì

DWORD WINAPI Consumer(LPVOID lpPara) { while(g_continue) { //×ÊÔ´ÐźÅÁ¿µÄP²Ù×÷

WaitForSingleObject(g_hEmptySemaphore,INFINITE); //»¥³âÐźÅÁ¿µÄP²Ù×÷

WaitForSingleObject(g_hMutex,INFINITE); //´Ó»º³åÇøÖÐÈ¡³öÒ»¸ö²úÆ· Take(); //Ïû·ÑÒ»¸ö²úÆ· Consume();

Sleep(2000);

//»¥³âÐźÅÁ¿µÄV²Ù×÷ ReleaseMutex(g_hMutex); //×ÊÔ´ÐźÅÁ¿µÄV²Ù×÷

ReleaseSemaphore(g_hFullSemaphore,1,NULL);

} return 0;

}

/*-----------------------------Ïû

·Ñ

Õß

Ïß

³Ì

½á

-------------------------------*/

/*---------------------------´´

½¨

Éú

²ú

Õß

Ïß

³Ì

¿ª

-----------------------------*/

void createPT()//´´½¨Éú²úÕßÏß³Ì {

Êø

ʼ

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)