- 博客(106)
- 资源 (18)
- 收藏
- 关注
原创 c++11条件变量的使用,condition_variable
void thread_prepare(int T){std::lock_guard lk(mt);data_queue.push(T);data_con.notify_one();}void thread_process(){while(1){std::unique_lock lk(mt);data_con.wait(lk,[]{return !data_queue.
2015-11-26 15:55:24
2273
原创 c++共享锁的使用
c++11未提供共享锁的实现,先使用boost的共享锁。#include boost::shared_mutex _mutex;boost::shared_lock mylock(_mutex);
2015-11-26 11:31:26
1175
原创 c++11细粒度的线程安全
void smallLockSize(){ std::unique_lock mylock(_mutex); hello(); mylock.unlock(); hello(); mylock.lock(); hello();}只有unique_lock可以使用细粒度的划分,即使用unlock以及locklock_guard等不可以
2015-11-26 11:03:27
627
原创 c++函数模板于类中的应用
class templateTest{public: template void process(func function) { function(); }}; templateTest tt; tt.process(hello);void hello(){ std::cout<<"hello"<<std::endl;}
2015-11-26 10:32:11
506
原创 c++11的mutex
#include #include std::list _list;std::mutex _mutex;void addList(int iValue){std::lock_guard guard(_mutex);_list.push_back(iValue);}bool list_contain(int valueToFind){std::lock_guard guard
2015-11-26 10:24:33
493
原创 vector 中生成一大批线程并等待完成
void f(){ std::vector threads; for(int j = 0 ; j <= 20 ; j++) //生成匿名线程添加到vector中 threads.push_back(std::thread(hello)); //调用每个thread的join std::for_each(threads.begin(),threads.end(),std::mem_
2015-11-24 10:58:56
1229
原创 线程参数之 unique_ptr
void process(std::unique_ptr);std::unique_ptr p (new obj);std::thread t(process,std::move(p));p的所有权先进入 thread t,而后进入process.
2015-11-24 09:58:44
1412
原创 线程的引用
线程 std::thread无视了引用参数,将自动改为副本func(para& pa);如要传入引用参数应使用std::thread t(func,std::ref(parameter));
2015-11-24 09:52:38
652
原创 c++11线程管理,RAII方式等待异常环境下线程结束
直接上代码class thread_guard{private: std::thread& t;public: explicit thread_guard(std::thread& _t):t(_t){} ~thread_guard() { if(t.joinable()) t.join(); }private: thread_guard(thread_guard
2015-11-21 16:33:10
1498
原创 第一个 c++11多线程
// Consolehello.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include void hello(){std::cout}int _tmain(int argc, _TCHAR* argv[]){for(int k = 0 ; k {std::
2015-11-18 22:47:58
583
原创 单例模式的 模板方式实现 c++
#ifndef SINGLETON_H#define SINGLETON_H#include templateclass singleton{public:static T& Instance(){if(!pInstance){pInstance = new T;}return *pInstance;}private:singleton();static T* pInstance;};templa
2015-09-18 19:28:12
1985
原创 智能指针用法
class msg{};void f(){std::auto_ptr m(new msg);}如此 ,在函数结束后指针会自动调用析构函数,即不会发生内存泄漏问题。
2015-09-17 16:43:08
374
原创 list与iterator用法实例
// list_.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include class Node{public:int id;Node(int _id){id = _id;};};int _tmain(int argc, _TCHAR* argv[]){
2015-09-02 10:59:20
4663
原创 C++ 范式工厂
#ifndef TEMPLATE_H#define TEMPLATE_H#include template class AbstractProduct,typename IdentifierType,class ProductCreator = AbstractProduct*(*)(),template class FactoryErrorPolicy = D
2015-08-26 13:51:56
1214
原创 c++ 设计模式之 策略模式与工厂模式结合
#include using namespace std;class COperation{public:int m_first;int m_second;virtual double getResult(){return 0;}};#define DECLARE_CLASS_CREATE(class_name) static CObject*
2015-08-24 15:44:20
1198
原创 c++ 设计模式之简单的工厂模式
调试环境:vs2010// test0.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include using namespace std;class COperation{public:int first;int second;virtual double getResult(){retu
2015-08-24 09:59:31
922
原创 基于消息机制的异步架构之对消息队列的处理
/* * handle.h */#ifndef HANDLE_H_#define HANDLE_H_#include "msgqueue.h"typedef struct HANDLER{int send_sock;char send_ip[128];uint16 send_port;int ind;pthread_t th
2015-08-11 20:35:20
3071
原创 基于消息机制的异步架构之回调函数注册
/* * akg.h * 业务逻辑注册 * */#ifndef AKG_H_#define AKG_H_#include "conn.h"#include "msgqueue.h"#define MAX_PKG_TYPE (0xffff)extern const ui
2015-08-11 20:27:40
1605
原创 日志系统的实现方式
linux下可运行日志系统的头文件#ifndef sysRecord_h#define sysRecord_h#include #include #include using namespace std;class sysRecord{public:ofstream m_file;time_t m_time_ptr;sysRecord();~
2015-08-11 20:13:28
1501
原创 基于消息机制的异步架构之消息队列
消息队列的头文件msgqueue.h/* * msgqueue.h * */#ifndef MSGQUEUE_H_#define MSGQUEUE_H_#include "conn.h"#define MAX_MSG_LENGTH (1024)typedef struct MSG {ch
2015-08-11 20:09:22
1506
原创 turnserver启动命令
root@VM-5-70-ubuntu:/etc/default# ./rfc5766-turn-server turnserver.confturnserver --listening-ip=119.29.85.xx测试:
2015-05-11 17:21:33
5398
转载 公开免费的stun服务器,解决内外网问题
http://blog.sina.com.cn/s/blog_683d26990100oucy.htmlstunserver.org 测试是OK的stun.xten.com / [$ y# L) M( t# y2 r" Z, E D! D% D8 I$ L0 V: H! S4 G) Q3 |" V7 f3 rstun.fwdnet.net 4 n2 a4 e! a6 p
2015-05-08 23:08:27
8750
1
原创 点击天数分析
data1元数据219precision:0.0401098901099recall:0.0566330488751f1:0.0469604374397大于25天点击168precision:0.0431654676259recall:0.0434445306439f1:0.0433045495554大于20天点击207preci
2015-04-10 21:07:38
566
原创 求两个文件交集
#!/usr/bin/env pythonrd3 = open('data_17_17_2.csv')base = open('data_17_17_3.csv')wr3 = open('delNoBuyed3DayAndStoreAndInCar4.5.2.csv','w+')bsData = base.readlines()i = 1for key in rd3:
2015-04-05 11:07:55
931
原创 删除没有购物行为的人
#!/usr/bin/env pythonrd = open('whoBuyWhat.csv')data3 = open('data_16_16_3.csv')wr3 = open('delNoBuyed4.5.1.csv','w+')rdt = rd.readlines()rdt_id = []for key in rdt: te = key.split(',')
2015-04-05 11:07:25
636
原创 验证集 某比赛
#!/usr/bin/env pythonfl = open('delNoBuyed4.5.1.csv')na = open('valia_17.csv')fl.readline()submit = fl.readlines()na17 = na.readlines()sub_num = len(submit)na_num = len(na17)ri = 0fo
2015-04-05 11:06:42
670
原创 按时间提取数据,某比赛
#!/usr/bin/env pythonfrom datetime import datetimefl = open('tianchi_mobile_recommend_train_user.csv')ns = open('data_16_16_3.csv','w+')#na = open('data_17_17_2.csv','w+')nsf = []naf = []
2015-04-05 11:06:04
574
原创 召回率,准确率,f1分析 某大赛1
前4天,通过购物车购买precision:0.0153313777615recall:0.177594903106f1:0.0282260616417前4天,通过收藏夹购买precision:0.00326368668608recall:0.0270772498009f1:0.00582524271845前4天 , 通过购物车&收藏夹购买precision:
2015-04-05 10:08:18
1178
原创 天池,改为开发包所需的文件输入
#!/usr/bin/env pythonfl = open('not.csv')wr = open('changeTpye.csv','w+')for key in fl: pt = key.split(',') wr.write(pt[0]+'::'+pt[1]+'::'+pt[2]+'::'+pt[4]) print ptfl.close()wr.clo
2015-04-02 22:07:06
825
原创 天池,删除地址
#!/usr/bin/env pythonfl = open('train.csv')wrr = open('no_time_but_add.csv','w+')for key in fl: pt = key.split(',') if pt[2] != '': wrr.write(key) print ptfl.close()wr.close(
2015-04-02 22:06:12
778
原创 天池,删除时间
#!/usr/bin/env pythonimport numpy as npfrom datetime import datetime#fl = open('te.csv')#item_id,item_geohash,item_categoryfl = open('tianchi_mobile_recommend_train_user.csv')#user_id,item
2015-04-02 22:05:16
778
原创 python读取并切分
#!/usr/bin/env pythonimport numpy as npfl = open('te.csv')try: text = fl.readline( )finally: print text #fl.close( )#print text#data = np.loadtxt("\usr\data\tianchi_mobile_recomm
2015-04-02 01:06:47
2758
原创 id3,没调试
#include "string.h"#include "iostream.h"#include "math.h"#define dataCol 4#define dataNum 4typedef int BOOL;struct data{BOOL line[dataCol];BOOL choosed;}dat[dataNum];
2015-03-09 15:46:51
756
原创 配置vc6+opencv1.0
全局设置 菜单Tools->Options->Directories:先设置lib路径,选择Library files,在下方填入路径: C:\Program Files\OpenCV\lib 然后选择include files,在下方填入路径: C:\Program Files\OpenCV\cxcore\include C
2015-03-03 20:21:16
1190
翻译 2013机器学习十大问题
1. Churn Prediction: Churn prediction is one of the most popular use cases for people who want to leverage machine learning. It has a large business value and benefit attached to itself specially
2015-02-28 13:44:06
700
Transact-SQL语句基础
2014-12-26
线程池,c++11,跨平台,支持vs12,g++最新的编译器,高效
2015-12-04
信息检索导论答案 introduction to information retrieval
2014-09-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅