#include "windows.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<fstream.h>
#include<io.h>
#include<string.h>
bool m_bSlow;
CProducerThread *m_pProducerThread;
CConsumerThread *m_pConsumerThread;
CSemaphore *m_pSemaphoreEmpty;
CSemaphore *m_pSemaphoreFull;
CMutex *m_pMutex;
CString m_sBufCSM;
CString m_sBuf;
CProducerThread::CProducerThread(void* hParent)
:m_pParentDlg(hParent)
{
}
int CProducerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)m_pParentDlg;
CSingleLock mutexLock(pDlg->m_pMutex);
for(int i=0;i
{
pDlg->m_pSemaphoreEmpty->Lock();
mutexLock.Lock();
pDlg->m_sBuf.Format("%0.10d",i);
mutexLock.Unlock();
pDlg->m_pSemaphoreFull->Unlock();
}
return CWinThread::Run();
}
CConsumerThread::CConsumerThread(void *pParent)
:m_pParent(pParent)
{
}
int CConsumerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)this->m_pParent;
char*pBuf;
pBuf=this->m_Data;
bool bSleep;
for(int i=0;i
{
pDlg->m_pSemaphoreFull->Lock();
pDlg->m_pMutex->Lock();
sprintf(pBuf,pDlg->m_sBuf);
bSleep=pDlg->m_bSlow ;
pDlg->m_pMutex->Unlock();
pBuf+=10;
if(pBuf>m_Data+CSM_BUF_COUNT-10)
pBuf=m_Data;
m_Data[CSM_BUF_COUNT]=0;
pDlg->m_pMutex->Lock();
sprintf(pDlg->m_sBufCSM.GetBuffer(CSM_BUF_COUNT+10),m_Data);
pDlg->m_pMutex->Unlock();
if (bSleep)
Sleep(100);
pDlg->m_pSemaphoreEmpty ->Unlock();
}
return CWinThread::Run();
}
void main()
{
m_pSemaphoreFull =new CSemaphore(1,1);
m_pSemaphoreEmpty =new CSemaphore(0,1);
m_pMutex =new CMutex;
this->m_bUpdateAuto =false;
this->m_pProducerThread =new CProducerThread(this);
this->m_pConsumerThread =new CConsumerThread(this);
this->m_sBuf.Format("1234567890");
this->UpdateData(false);
this->m_pProducerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pProducerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pConsumerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pConsumerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pProducerThread->ResumeThread();
this->m_pConsumerThread->ResumeThread();
}
--------------------Configuration: d - Win32 Debug--------------------
Compiling...
d.cpp
F:\C++\zuoye\d.cpp(30) : error C2143: syntax error : missing ';' before '*'
F:\C++\zuoye\d.cpp(30) : error C2501: 'CProducerThread' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(30) : error C2501: 'm_pProducerThread' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(31) : error C2143: syntax error : missing ';' before '*'
F:\C++\zuoye\d.cpp(31) : error C2501: 'CConsumerThread' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(31) : error C2501: 'm_pConsumerThread' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(33) : error C2143: syntax error : missing ';' before '*'
F:\C++\zuoye\d.cpp(33) : error C2501: 'CSemaphore' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(33) : error C2501: 'm_pSemaphoreEmpty' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(34) : error C2143: syntax error : missing ';' before '*'
F:\C++\zuoye\d.cpp(34) : error C2501: 'CSemaphore' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(34) : error C2086: 'CSemaphore' : redefinition
F:\C++\zuoye\d.cpp(34) : error C2501: 'm_pSemaphoreFull' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(36) : error C2143: syntax error : missing ';' before '*'
F:\C++\zuoye\d.cpp(36) : error C2501: 'CMutex' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(36) : error C2501: 'm_pMutex' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(38) : error C2146: syntax error : missing ';' before identifier 'm_sBufCSM'
F:\C++\zuoye\d.cpp(38) : error C2501: 'CString' : missing storage-class or type specifiers
F:\C++\zuoye\d.cpp(38) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
d.exe - 19 error(s), 0 warning(s)
到底怎么修改啊
我是菜鸟啊
谢谢!!!!!!!!!!!!!!
6 个解决方案
#1
bool m_bSlow;//注意后面的';'//很多地方
在头文件加#include <afxmt.h>
还有因为没有CProducerThread类的声明(定义),所以我们是不可能帮你调的。
在头文件加#include <afxmt.h>
还有因为没有CProducerThread类的声明(定义),所以我们是不可能帮你调的。
#2
天哪!
真的是这个程序的吗?
真的是这个程序的吗?
#3
帮你改到只剩下两处错误
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<fstream.h>
#include<iostream.h>
#include<string.h>
bool m_bSlow
CProducerThread *m_pProducerThread;
CConsumerThread *m_pConsumerThread;
CSemaphore *m_pSemaphoreEmpty;
CSemaphore *m_pSemaphoreFull;
CMutex *m_pMutex;
CString m_sBufCSM;
CString m_sBuf;
CProducerThread::CProducerThread(void* hParent) :m_pParentDlg(hParent)
{
}
int CProducerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)m_pParentDlg;
CSingleLock mutexLock(pDlg->m_pMutex);
for(int i=0;;)
{
pDlg->m_pSemaphoreEmpty->Lock();
mutexLock.Lock();
pDlg->m_sBuf.Format("%0.10d",i);
mutexLock.Unlock();
pDlg->m_pSemaphoreFull->Unlock();
}
return CWinThread::Run();
}
CConsumerThread::CConsumerThread(void *pParent) :m_pParent(pParent)
{
}
int CConsumerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)this->m_pParent;
char*pBuf;
pBuf=this->m_Data;
bool bSleep;
for(int i=0;;)
{
pDlg->m_pSemaphoreFull->Lock();
pDlg->m_pMutex->Lock();
sprintf(pBuf,pDlg->m_sBuf);
bSleep=pDlg->m_bSlow ;
pDlg->m_pMutex->Unlock();
pBuf+=10;
if(pBuf>m_Data+CSM_BUF_COUNT-10)
pBuf=m_Data;
m_Data[CSM_BUF_COUNT]=0;
pDlg->m_pMutex->Lock();
sprintf(pDlg->m_sBufCSM.GetBuffer(CSM_BUF_COUNT+10),m_Data);
pDlg->m_pMutex->Unlock();
if (bSleep)
Sleep(100);
pDlg->m_pSemaphoreEmpty ->Unlock();
}
return CWinThread::Run();
}
void main()
{
m_pSemaphoreFull =new CSemaphore(1,1);
m_pSemaphoreEmpty =new CSemaphore(0,1);
m_pMutex =new CMutex;
this->m_bUpdateAuto =false;
this->m_pProducerThread =new CProducerThread(this);
this->m_pConsumerThread =new CConsumerThread(this);
this->m_sBuf.Format("1234567890");
this->UpdateData(false);
this->m_pProducerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pProducerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pConsumerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pConsumerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pProducerThread->ResumeThread();
this->m_pConsumerThread->ResumeThread();
}
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<fstream.h>
#include<iostream.h>
#include<string.h>
bool m_bSlow
CProducerThread *m_pProducerThread;
CConsumerThread *m_pConsumerThread;
CSemaphore *m_pSemaphoreEmpty;
CSemaphore *m_pSemaphoreFull;
CMutex *m_pMutex;
CString m_sBufCSM;
CString m_sBuf;
CProducerThread::CProducerThread(void* hParent) :m_pParentDlg(hParent)
{
}
int CProducerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)m_pParentDlg;
CSingleLock mutexLock(pDlg->m_pMutex);
for(int i=0;;)
{
pDlg->m_pSemaphoreEmpty->Lock();
mutexLock.Lock();
pDlg->m_sBuf.Format("%0.10d",i);
mutexLock.Unlock();
pDlg->m_pSemaphoreFull->Unlock();
}
return CWinThread::Run();
}
CConsumerThread::CConsumerThread(void *pParent) :m_pParent(pParent)
{
}
int CConsumerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)this->m_pParent;
char*pBuf;
pBuf=this->m_Data;
bool bSleep;
for(int i=0;;)
{
pDlg->m_pSemaphoreFull->Lock();
pDlg->m_pMutex->Lock();
sprintf(pBuf,pDlg->m_sBuf);
bSleep=pDlg->m_bSlow ;
pDlg->m_pMutex->Unlock();
pBuf+=10;
if(pBuf>m_Data+CSM_BUF_COUNT-10)
pBuf=m_Data;
m_Data[CSM_BUF_COUNT]=0;
pDlg->m_pMutex->Lock();
sprintf(pDlg->m_sBufCSM.GetBuffer(CSM_BUF_COUNT+10),m_Data);
pDlg->m_pMutex->Unlock();
if (bSleep)
Sleep(100);
pDlg->m_pSemaphoreEmpty ->Unlock();
}
return CWinThread::Run();
}
void main()
{
m_pSemaphoreFull =new CSemaphore(1,1);
m_pSemaphoreEmpty =new CSemaphore(0,1);
m_pMutex =new CMutex;
this->m_bUpdateAuto =false;
this->m_pProducerThread =new CProducerThread(this);
this->m_pConsumerThread =new CConsumerThread(this);
this->m_sBuf.Format("1234567890");
this->UpdateData(false);
this->m_pProducerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pProducerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pConsumerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pConsumerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pProducerThread->ResumeThread();
this->m_pConsumerThread->ResumeThread();
}
#4
还有因为没有CProducerThread类的声明(定义),所以我们是不可能帮你调的。
#5
这是操作系统中,必学的知识,
一个好好的程序,你自己不要乱改,就是改了,你自己可以测试吗?自己没有动手的能力,你又何必动它 呢?好好地看,读。其实你只要看的程序多了,水平自然就上去了!刚开始,不要急!
向生产者,进餐,还有北大,复旦,他们出的考题,你多看看,为什么这样?多思考
就像C,和,汇编,好多固定的格式,和你以前的思维完全不一样,在编程序之前,你必须对它定义,因为机器语言太麻烦,所以咱们就得学会符号语言,所以你必须对它定义,指出它的类型,计算机才会从内存中读取数据!
不要刚开始就搞这样的!
一个好好的程序,你自己不要乱改,就是改了,你自己可以测试吗?自己没有动手的能力,你又何必动它 呢?好好地看,读。其实你只要看的程序多了,水平自然就上去了!刚开始,不要急!
向生产者,进餐,还有北大,复旦,他们出的考题,你多看看,为什么这样?多思考
就像C,和,汇编,好多固定的格式,和你以前的思维完全不一样,在编程序之前,你必须对它定义,因为机器语言太麻烦,所以咱们就得学会符号语言,所以你必须对它定义,指出它的类型,计算机才会从内存中读取数据!
不要刚开始就搞这样的!
#6
都有提示错误了,还看不出来啊
#1
bool m_bSlow;//注意后面的';'//很多地方
在头文件加#include <afxmt.h>
还有因为没有CProducerThread类的声明(定义),所以我们是不可能帮你调的。
在头文件加#include <afxmt.h>
还有因为没有CProducerThread类的声明(定义),所以我们是不可能帮你调的。
#2
天哪!
真的是这个程序的吗?
真的是这个程序的吗?
#3
帮你改到只剩下两处错误
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<fstream.h>
#include<iostream.h>
#include<string.h>
bool m_bSlow
CProducerThread *m_pProducerThread;
CConsumerThread *m_pConsumerThread;
CSemaphore *m_pSemaphoreEmpty;
CSemaphore *m_pSemaphoreFull;
CMutex *m_pMutex;
CString m_sBufCSM;
CString m_sBuf;
CProducerThread::CProducerThread(void* hParent) :m_pParentDlg(hParent)
{
}
int CProducerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)m_pParentDlg;
CSingleLock mutexLock(pDlg->m_pMutex);
for(int i=0;;)
{
pDlg->m_pSemaphoreEmpty->Lock();
mutexLock.Lock();
pDlg->m_sBuf.Format("%0.10d",i);
mutexLock.Unlock();
pDlg->m_pSemaphoreFull->Unlock();
}
return CWinThread::Run();
}
CConsumerThread::CConsumerThread(void *pParent) :m_pParent(pParent)
{
}
int CConsumerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)this->m_pParent;
char*pBuf;
pBuf=this->m_Data;
bool bSleep;
for(int i=0;;)
{
pDlg->m_pSemaphoreFull->Lock();
pDlg->m_pMutex->Lock();
sprintf(pBuf,pDlg->m_sBuf);
bSleep=pDlg->m_bSlow ;
pDlg->m_pMutex->Unlock();
pBuf+=10;
if(pBuf>m_Data+CSM_BUF_COUNT-10)
pBuf=m_Data;
m_Data[CSM_BUF_COUNT]=0;
pDlg->m_pMutex->Lock();
sprintf(pDlg->m_sBufCSM.GetBuffer(CSM_BUF_COUNT+10),m_Data);
pDlg->m_pMutex->Unlock();
if (bSleep)
Sleep(100);
pDlg->m_pSemaphoreEmpty ->Unlock();
}
return CWinThread::Run();
}
void main()
{
m_pSemaphoreFull =new CSemaphore(1,1);
m_pSemaphoreEmpty =new CSemaphore(0,1);
m_pMutex =new CMutex;
this->m_bUpdateAuto =false;
this->m_pProducerThread =new CProducerThread(this);
this->m_pConsumerThread =new CConsumerThread(this);
this->m_sBuf.Format("1234567890");
this->UpdateData(false);
this->m_pProducerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pProducerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pConsumerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pConsumerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pProducerThread->ResumeThread();
this->m_pConsumerThread->ResumeThread();
}
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<fstream.h>
#include<iostream.h>
#include<string.h>
bool m_bSlow
CProducerThread *m_pProducerThread;
CConsumerThread *m_pConsumerThread;
CSemaphore *m_pSemaphoreEmpty;
CSemaphore *m_pSemaphoreFull;
CMutex *m_pMutex;
CString m_sBufCSM;
CString m_sBuf;
CProducerThread::CProducerThread(void* hParent) :m_pParentDlg(hParent)
{
}
int CProducerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)m_pParentDlg;
CSingleLock mutexLock(pDlg->m_pMutex);
for(int i=0;;)
{
pDlg->m_pSemaphoreEmpty->Lock();
mutexLock.Lock();
pDlg->m_sBuf.Format("%0.10d",i);
mutexLock.Unlock();
pDlg->m_pSemaphoreFull->Unlock();
}
return CWinThread::Run();
}
CConsumerThread::CConsumerThread(void *pParent) :m_pParent(pParent)
{
}
int CConsumerThread::Run()
{
CP_CDlg *pDlg;
pDlg=(CP_CDlg*)this->m_pParent;
char*pBuf;
pBuf=this->m_Data;
bool bSleep;
for(int i=0;;)
{
pDlg->m_pSemaphoreFull->Lock();
pDlg->m_pMutex->Lock();
sprintf(pBuf,pDlg->m_sBuf);
bSleep=pDlg->m_bSlow ;
pDlg->m_pMutex->Unlock();
pBuf+=10;
if(pBuf>m_Data+CSM_BUF_COUNT-10)
pBuf=m_Data;
m_Data[CSM_BUF_COUNT]=0;
pDlg->m_pMutex->Lock();
sprintf(pDlg->m_sBufCSM.GetBuffer(CSM_BUF_COUNT+10),m_Data);
pDlg->m_pMutex->Unlock();
if (bSleep)
Sleep(100);
pDlg->m_pSemaphoreEmpty ->Unlock();
}
return CWinThread::Run();
}
void main()
{
m_pSemaphoreFull =new CSemaphore(1,1);
m_pSemaphoreEmpty =new CSemaphore(0,1);
m_pMutex =new CMutex;
this->m_bUpdateAuto =false;
this->m_pProducerThread =new CProducerThread(this);
this->m_pConsumerThread =new CConsumerThread(this);
this->m_sBuf.Format("1234567890");
this->UpdateData(false);
this->m_pProducerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pProducerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pConsumerThread->CreateThread(CREATE_SUSPENDED);
VERIFY(m_pConsumerThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
this->m_pProducerThread->ResumeThread();
this->m_pConsumerThread->ResumeThread();
}
#4
还有因为没有CProducerThread类的声明(定义),所以我们是不可能帮你调的。
#5
这是操作系统中,必学的知识,
一个好好的程序,你自己不要乱改,就是改了,你自己可以测试吗?自己没有动手的能力,你又何必动它 呢?好好地看,读。其实你只要看的程序多了,水平自然就上去了!刚开始,不要急!
向生产者,进餐,还有北大,复旦,他们出的考题,你多看看,为什么这样?多思考
就像C,和,汇编,好多固定的格式,和你以前的思维完全不一样,在编程序之前,你必须对它定义,因为机器语言太麻烦,所以咱们就得学会符号语言,所以你必须对它定义,指出它的类型,计算机才会从内存中读取数据!
不要刚开始就搞这样的!
一个好好的程序,你自己不要乱改,就是改了,你自己可以测试吗?自己没有动手的能力,你又何必动它 呢?好好地看,读。其实你只要看的程序多了,水平自然就上去了!刚开始,不要急!
向生产者,进餐,还有北大,复旦,他们出的考题,你多看看,为什么这样?多思考
就像C,和,汇编,好多固定的格式,和你以前的思维完全不一样,在编程序之前,你必须对它定义,因为机器语言太麻烦,所以咱们就得学会符号语言,所以你必须对它定义,指出它的类型,计算机才会从内存中读取数据!
不要刚开始就搞这样的!
#6
都有提示错误了,还看不出来啊