mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
add sample box which can use acl::mbox, acl::tbox and acl::tbox_array
This commit is contained in:
parent
0dfd2d45c7
commit
c0437bb1de
2
lib_acl_cpp/samples/box/Makefile
Normal file
2
lib_acl_cpp/samples/box/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
include ../Makefile.in
|
||||
PROG = box
|
47
lib_acl_cpp/samples/box/box.cpp
Normal file
47
lib_acl_cpp/samples/box/box.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#define BOX acl::mbox
|
||||
//#define BOX acl::tbox
|
||||
//#define BOX acl::tbox_array
|
||||
|
||||
class producer : public acl::thread
|
||||
{
|
||||
public:
|
||||
producer(BOX<int>& box, int max) : box_(box), max_(max) {}
|
||||
~producer(void) {}
|
||||
|
||||
protected:
|
||||
void* run(void)
|
||||
{
|
||||
for (int i = 0; i < max_; i++) {
|
||||
int* n = new int;
|
||||
*n = i;
|
||||
box_.push(n);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
BOX<int>& box_;
|
||||
int max_;
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int max = 50000000;
|
||||
BOX<int> box;
|
||||
|
||||
producer thr(box, max);
|
||||
thr.start();
|
||||
|
||||
for (int i = 0; i < max; i++) {
|
||||
int* n = box.pop();
|
||||
assert(*n == i);
|
||||
delete n;
|
||||
}
|
||||
|
||||
printf("All over, max=%d\r\n", max);
|
||||
thr.wait();
|
||||
return 0;
|
||||
}
|
8
lib_acl_cpp/samples/box/stdafx.cpp
Normal file
8
lib_acl_cpp/samples/box/stdafx.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
||||
// master_threads.pch 将成为预编译头
|
||||
// stdafx.obj 将包含预编译类型信息
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: 在 STDAFX.H 中
|
||||
//引用任何所需的附加头文件,而不是在此文件中引用
|
19
lib_acl_cpp/samples/box/stdafx.h
Normal file
19
lib_acl_cpp/samples/box/stdafx.h
Normal file
@ -0,0 +1,19 @@
|
||||
// stdafx.h : 标准系统包含文件的包含文件,
|
||||
// 或是常用但不常更改的项目特定的包含文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
//#include <iostream>
|
||||
//#include <tchar.h>
|
||||
|
||||
// TODO: 在此处引用程序要求的附加头文件
|
||||
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
#include "acl_cpp/stdlib/tbox_array.hpp"
|
||||
|
||||
#ifdef WIN32
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user