|
为什么提示ACE_Local_Mutex未定义?是操作系统不支持吗?
在windows xp下用vc++2003编译,代码如下:
#include "ace\Task.h"
#include "ace\Synch.h"
#include "ace\Thread.h"
#include "ace\Log_Msg.h"
#include "ace\OS.h"
#include "ace\Token.h"
#include "ace\Local_Tokens.h"
typedef struct device
{
int id;
}Device;
class DeviceRepository
{
public:
enum { N_DEVICES = 100 };
DeviceRepository()
{
for( int i = 0; i < N_DEVICES; i++ )
{
token_ = new ACE_Local_Mutex( 0, 0, 1 );
devices_ = new Device;
devices_->id = i;
}
}
~DeviceRepository()
{
for( int i = 0; i < N_DEVICES; i++ )
{
delete token_;
}
}
int updateDevice( int deviceID, char *commands )
{
ACE_DEBUG((LM_DEBUG, "Update Device %d\n", deviceID));
token_[deviceID]->acquire();
Device *currDevice = devices_[deviceID];
internalDo(currDevice);
token_[deviceID]->release();
return 0;
}
void internalDo( Device *d )
{
ACE_OS::sleep(1);
}
private:
Device *devices_[N_DEVICES];
ACE_Local_Mutex *token_[N_DEVICES];
};
class CommandHandler : public ACE_Task< ACE_MT_SYNCH >
{
public:
enum{ N_THREADS = 5 };
CommandHandler( DeviceRepository &dr )
:dr_(dr)
{
}
virtual int svc(void)
{
for (int i = 0; i < DeviceRepository::N_DEVICES; i++)
{
dr_.updateDevice( i, "" );
}
}
private:
DeviceRepository &dr_;
};
int main( int argc, char *argv[] )
{
ACE_UNUSED_ARG( argc );
ACE_UNUSED_ARG( argv );
DeviceRepository dr;
CommandHandler ch( dr );
ch.activate( THR_NEW_LWP | THR_JOINABLE, CommandHandler::N_THREADS );
ch.wait();
return 0;
}
[ 本帖最后由 pengxiqin 于 2009-11-10 00:13 编辑 ] |
|