不会写博客。慢慢学着写吧。将chromium的base模块分离出来,使用thread方式
#include "stdafx.h"
#include<string>
#include "./base/threading/thread.h"
#include "./base/bind.h"
#include "./base/callback.h"
#include "./base/message_loop/message_loop.h"
#include "./base/at_exit.h"
#pragma comment(lib,"base.lib")
#pragma comment(lib,"base_static.lib")
#pragma comment(lib,"dynamic_annotations.lib")
#pragma comment(lib,"DbgHelp.lib")
#pragma comment(lib,"Psapi.lib")
struct kaka
{
int mmm ;
std::string mmol;
std::string mollo;
};
class FilePathWatcherTest
{
public:
FilePathWatcherTest()
: file_thread_("FilePathWatcherTest1") {
SetUp();
}
virtual ~FilePathWatcherTest() {}
void dosomework(kaka *wo);
bool SetupWatch(kaka &oo_) ;
protected:
virtual void SetUp() {
// Create a separate file thread in order to test proper thread usage.
base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
file_thread_.StartWithOptions(options);
}
base::Thread file_thread_;
};
void FilePathWatcherTest::dosomework(kaka *wo)
{
printf("%d",wo->mmm);
printf("donghai \n");
{
file_thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&FilePathWatcherTest::dosomework, base::Unretained(this), base::Unretained(&oo_))
);
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
base :: AtExitManager exit_manager;
FilePathWatcherTest pp;
kaka wo[10];
for (int i=0; i <10 ; i++)
{
wo[i].mmm = i;
Sleep(2);
pp.SetupWatch(wo[i]);
}
while (1);
return 0;
}
#include "stdafx.h"
#include<string>
#include "./base/threading/thread.h"
#include "./base/bind.h"
#include "./base/callback.h"
#include "./base/message_loop/message_loop.h"
#include "./base/at_exit.h"
#pragma comment(lib,"base.lib")
#pragma comment(lib,"base_static.lib")
#pragma comment(lib,"dynamic_annotations.lib")
#pragma comment(lib,"DbgHelp.lib")
#pragma comment(lib,"Psapi.lib")
struct kaka
{
int mmm ;
std::string mmol;
std::string mollo;
};
class FilePathWatcherTest
{
public:
FilePathWatcherTest()
: file_thread_("FilePathWatcherTest1") {
SetUp();
}
virtual ~FilePathWatcherTest() {}
void dosomework(kaka *wo);
bool SetupWatch(kaka &oo_) ;
protected:
virtual void SetUp() {
// Create a separate file thread in order to test proper thread usage.
base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
file_thread_.StartWithOptions(options);
}
base::Thread file_thread_;
};
void FilePathWatcherTest::dosomework(kaka *wo)
{
printf("%d",wo->mmm);
printf("donghai \n");
}
bool FilePathWatcherTest::SetupWatch(kaka &oo_){
file_thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&FilePathWatcherTest::dosomework, base::Unretained(this), base::Unretained(&oo_))
);
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
base :: AtExitManager exit_manager;
FilePathWatcherTest pp;
kaka wo[10];
for (int i=0; i <10 ; i++)
{
wo[i].mmm = i;
Sleep(2);
pp.SetupWatch(wo[i]);
}
while (1);
return 0;
}