{"id":8964,"date":"2024-05-19T18:01:01","date_gmt":"2024-05-19T10:01:01","guid":{"rendered":""},"modified":"2024-05-19T18:01:01","modified_gmt":"2024-05-19T10:01:01","slug":"\u53cc\u7f13\u51b2\u7684\u8a89\u6284\u7684\u8fc7\u7a0b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8964.html","title":{"rendered":"\u53cc\u7f13\u51b2\u7684\u8a89\u6284\u7684\u8fc7\u7a0b"},"content":{"rendered":"
\u7a0b\u5e8f\u4e00\u5229\u7528\u53cc\u7f13\u51b2\u3001\u4e09\u7ebf\u7a0b\u7684\u4e32\u884c\u6267\u884c\u5b9e\u73b0\u4ece\u8f93\u5165\u6587\u4ef6\u5230\u5c4f\u5e55\u7684\u62f7\u8d1d\u8f93\u51fa\uff1a<\/p>\n
\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
#include<windows.h><\/p>\n
#include<iostream><\/p>\n
using namespacestd;<\/p>\n
FILE *infile;<\/p>\n
char buf1,buf2;<\/p>\n
void get(){buf1=fgetc(infile);}<\/p>\n
void copy(){buf2=buf1;}<\/p>\n
void put( ){putchar(buf2);}<\/p>\n
int main()<\/p>\n
{
\n <\/p>\n
infile=fopen(\"in.txt\",\"r\");<\/p>\n
for(;buf1!=EOF;)<\/p>\n
{
\n <\/p>\n
get();<\/p>\n
copy();<\/p>\n
put();<\/p>\n
}<\/p>\n
fclose(infile);<\/p>\n
return 0;<\/p>\n
}<\/p>\n
<\/p>\n
<\/p>\n
\u7a0b\u5e8f\u4e8c\u5b9e\u73b0\u7ebf\u7a0b\u7684\u968f\u673a\u5e76\u53d1\u6267\u884c\uff1a <\/p>\n
\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
#include <cstdio><\/p>\n
#include \"conio.h\"<\/p>\n
#include \"windows.h\"<\/p>\n
#include <iostream><\/p>\n
using namespace std;<\/p>\n
typedef struct _THREADDATA<\/p>\n
{
\n <\/p>\n
FILE*infile;<\/p>\n
char*buf1;<\/p>\n
char*buf2;<\/p>\n
}*LPTHREADDATA, THREADDATA;<\/p>\n
DWORD WINAPI get(LPVOID lParam)<\/p>\n
{
\n <\/p>\n
LPTHREADDATA pData = (LPTHREADDATA)lParam;<\/p>\n
for (;*pData->buf1!=EOF;) <\/p>\n
{
\n <\/p>\n
*pData->buf1=fgetc(pData->infile); <\/p>\n
Sleep(1);<\/p>\n
}<\/p>\n
return 0;<\/p>\n
}<\/p>\n
DWORD WINAPI copy(LPVOID lParam)<\/p>\n
{
\n <\/p>\n
LPTHREADDATA pData = (LPTHREADDATA)lParam; <\/p>\n
for (;*pData->buf1!=EOF;) <\/p>\n
*pData->buf2=*pData->buf1;<\/p>\n
return0;<\/p>\n
}<\/p>\n
DWORD WINAPI put(LPVOID lParam)<\/p>\n
{
\n <\/p>\n
LPTHREADDATA pData = (LPTHREADDATA)lParam;<\/p>\n
for (;*pData->buf1!=EOF;) <\/p>\n
{
\n <\/p>\n
cout<<*pData->buf2<<endl;<\/p>\n
Sleep(1);<\/p>\n
}<\/p>\n
return 0;<\/p>\n
}<\/p>\n
int main()<\/p>\n
{
\n <\/p>\n
FILE*infile=fopen(\"in.txt\",\"r\");<\/p>\n
charbuf1,buf2;<\/p>\n
LPTHREADDATA pData = new THREADDATA;<\/p>\n
pData->infile=infile;<\/p>\n
pData->buf1=&buf1;<\/p>\n
pData->buf2=&buf2;;<\/p>\n
DWORD ThreadId1,ThreadId2,ThreadId3;<\/p>\n
::CreateThread(NULL,0, get, (LPVOID)pData, 0, &ThreadId1); <\/p>\n
::CreateThread(NULL,0, copy, (LPVOID)pData, 0, &ThreadId2); <\/p>\n
::CreateThread(NULL,0, put, (LPVOID)pData, 0, &ThreadId3); <\/p>\n
getch();<\/p>\n
fclose(infile);<\/p>\n
return0;<\/p>\n
}<\/p>\n
<\/p>\n
\u7a0b\u5e8f\u4e09\u63a7\u5236\u8fdb\u7a0b\u5b9e\u73b0\u6b63\u786e\u7684\u5e76\u53d1\u8a8a\u6284\uff1a <\/p>\n
\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
\n
#include <cstdio><\/p>\n
#include \"conio.h\"<\/p>\n
#include \"windows.h\"<\/p>\n
#include <iostream><\/p>\n
using namespace std;<\/p>\n
HANDLE Mutex; <\/p>\n
HANDLE buf1_e;<\/p>\n
HANDLE buf1_f;<\/p>\n
HANDLE buf2_e;<\/p>\n
HANDLE buf2_f;<\/p>\n
typedef struct _THREADDATA<\/p>\n
{
\n <\/p>\n
FILE*infile;<\/p>\n
char*buf1;<\/p>\n
char*buf2;<\/p>\n
}*LPTHREADDATA, THREADDATA;<\/p>\n
DWORD WINAPI get(LPVOID lParam)<\/p>\n
{
\n <\/p>\n
LPTHREADDATApData = (LPTHREADDATA)lParam;<\/p>\n
for (;*pData->buf1!=EOF;) <\/p>\n
{
\n <\/p>\n
WaitForSingleObject(buf1_e,INFINITE);<\/p>\n
*pData->buf1=fgetc(pData->infile); <\/p>\n
ReleaseSemaphore(buf1_f,1,NULL);<\/p>\n
}<\/p>\n
return 0;<\/p>\n
}<\/p>\n
<\/p>\n
DWORD WINAPI copy(LPVOID lParam)<\/p>\n
{
\n <\/p>\n
LPTHREADDATApData = (LPTHREADDATA)lParam;<\/p>\n
for (;*pData->buf1!=EOF;) <\/p>\n
{
\n <\/p>\n
WaitForSingleObject(buf1_f,INFINITE);<\/p>\n
WaitForSingleObject(buf2_e,INFINITE);<\/p>\n
*pData->buf2=*pData->buf1;<\/p>\n
ReleaseSemaphore(buf1_e,1,NULL);<\/p>\n
ReleaseSemaphore(buf2_f,1,NULL);<\/p>\n
}<\/p>\n
return 0;<\/p>\n
}<\/p>\n
DWORD WINAPI put(LPVOID lParam)<\/p>\n
{
\n <\/p>\n
LPTHREADDATApData = (LPTHREADDATA)lParam;<\/p>\n
for (;*pData->buf1!=EOF;) <\/p>\n
{
\n <\/p>\n
WaitForSingleObject(buf2_f,INFINITE);<\/p>\n
cout<<*pData->buf2;<\/p>\n
ReleaseSemaphore(buf2_e,1,NULL);<\/p>\n
}<\/p>\n
return 0;<\/p>\n
}<\/p>\n
int main()<\/p>\n
{
\n <\/p>\n
\/\/ Mutex=CreateMutex(NULL,FALSE,NULL); <\/p>\n
buf1_e=CreateSemaphore(NULL,1,1,NULL);<\/p>\n
buf1_f=CreateSemaphore(NULL,0,1,NULL);<\/p>\n
buf2_e=CreateSemaphore(NULL,1,1,NULL);<\/p>\n
buf2_f=CreateSemaphore(NULL,0,1,NULL);<\/p>\n
FILE*infile=fopen(\"in.txt\",\"r\");<\/p>\n
charbuf1,buf2;<\/p>\n
LPTHREADDATA pData = new THREADDATA;<\/p>\n
pData->infile=infile;<\/p>\n
pData->buf1=&buf1;<\/p>\n
pData->buf2=&buf2;<\/p>\n
DWORDThreadId1,ThreadId2,ThreadId3;<\/p>\n
::CreateThread(NULL,0, copy, (LPVOID)pData, 0, &ThreadId2); <\/p>\n
::CreateThread(NULL,0, put, (LPVOID)pData, 0, &ThreadId3); <\/p>\n
::CreateThread(NULL,0, get, (LPVOID)pData, 0, &ThreadId1); <\/p>\n
getch();<\/p>\n
fclose(infile);<\/p>\n
return 0;<\/p>\n
}
\n <\/p>\n
<\/p>\n","protected":false},"excerpt":{"rendered":"\u53cc\u7f13\u51b2\u7684\u8a89\u6284\u7684\u8fc7\u7a0b\u7a0b\u5e8f\u4e00\u5229\u7528\u53cc\u7f13\u51b2\u3001\u4e09\u7ebf\u7a0b\u7684\u4e32\u884c\u6267\u884c\u5b9e\u73b0\u4ece\u8f93\u5165\u6587\u4ef6\u5230\u5c4f\u5e55\u7684\u62f7\u8d1d\u8f93\u51fa\uff1a\u4ee3\u7801\u5982\u4e0b\uff1a#include#includeusingna...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8964"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8964"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8964\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}