add sample box which can use acl::mbox, acl::tbox and acl::tbox_array

This commit is contained in:
zsx 2019-03-14 10:17:36 +08:00
parent 0dfd2d45c7
commit c0437bb1de
4 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,2 @@
include ../Makefile.in
PROG = box

View 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;
}

View File

@ -0,0 +1,8 @@
// stdafx.cpp : 只包括标准包含文件的源文件
// master_threads.pch 将成为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
//引用任何所需的附加头文件,而不是在此文件中引用

View 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