自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(17)
  • 收藏
  • 关注

转载 2021-07-21

可重入的mutex基本概念基本实现基本概念可重入锁(Reentrant Lock),是指允许同一个线程多次对该锁进行acquire动作。对于不可重入的锁,当一个线程多次调用acquire后将造成死锁。基本实现自己实现一个可重入锁并不困难:我们增加两个field,一个用来记录锁当前被哪个线程拥有;一个用来记录尝试acquire的次数。下面展示一些 内联代码片。// A code blockvar foo = 'bar';#include <stdint.h>#include &

2021-07-21 11:18:40 62

转载 2021-07-21

C++智能指针scoped_ptr的原理和使用欢迎使用Markdown编辑器成员函数讲解scoped_ptr(scoped_ptr const &)和scoped_ptr & operator=(scoped_ptr const &)explicit scoped_ptr(T* p=0)~scoped_ptr()void reset(T* p=0)T& operator*() const;T* operator->() const;T* get() const;oper

2021-07-21 09:27:01 77

转载 使用Vundle安装YouCompleteMe

下载Vundle$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim配置Vundle将如下内容复制到.vimrc最上方。set nocompatible " be iMproved, requiredfiletype off " required" set the runtime path to include Vundle and initializeset rtp+=~/.vi.

2020-09-23 20:22:44 370

原创 clientServer01简单版

client01端#define WIN32_LEAN_AND_MEAN#include<windows.h>#include<WinSock2.h>#include<iostream>#pragma comment(lib,"ws2_32.lib")//动态链接库//可以在属性的链接库中添加int main1_0(){ //启动W...

2020-09-23 20:18:48 88

原创 clientserver02简单网络通信

client02#define WIN32_LEAN_AND_MEAN#define _CRT_SECURE_NO_WARNINGS#include<windows.h>#include<WinSock2.h>#include<iostream>#include<stdio.h>using namespace std;#pr...

2020-09-23 20:18:31 100

原创 简单网络通信03

client03#define WIN32_LEAN_AND_MEAN#define _CRT_SECURE_NO_WARNINGS#include<windows.h>#include<WinSock2.h>#include<iostream>#include<stdio.h>using namespace std;#pr...

2020-09-23 20:18:11 83

原创 select01网络通信

Server01#define WIN32_LEAN_AND_MEAN#include<windows.h>#include<WinSock2.h>#include<iostream>#pragma comment(lib,"ws2_32.lib")//动态链接库//可以在属性的链接库中添加enum CMD{ CMD_LOGIN,...

2020-09-23 20:17:49 68

原创 select网络通信02

client02#define WIN32_LEAN_AND_MEAN#define _CRT_SECURE_NO_WARNINGS#include<windows.h>#include<WinSock2.h>#include<iostream>#include<stdio.h>using namespace std;#prag...

2020-09-23 20:17:11 91

原创 面向select网络编程转化为面向对象

数据包#ifndef _MessageHeader_hpp_#define _MessageHeader_hpp_enum CMD{ CMD_LOGIN, CMD_LOGIN_RESULT, CMD_LOGOUT, CMD_LOGOUT_RESULT, CMD_NEW_USER_JOIN, CMD_ERROR};//文件头stru...

2020-09-23 20:16:58 74

原创 面向对象的select网络模型加上防止粘包、根据数据头所提供的长度进行接收发数据

数据包格式#ifndef _MessageHeader_hpp_#define _MessageHeader_hpp_enum CMD{ CMD_LOGIN, CMD_LOGIN_RESULT, CMD_LOGOUT, CMD_LOGOUT_RESULT, CMD_NEW_USER_JOIN, CMD_ERROR};//文件头st...

2020-09-23 20:16:41 159

原创 一种达到微妙级别的计时器

#ifndef _CELLTimestamp_hpp_#define _CELLTimestamp_hpp_//为了避免同一个头文件被包含(include)多次,C/C++中有两种宏实现方式://一种是#ifndef方式;另一种是#pragma once方式。#pragma once// 达到微秒的计时器#include<chrono>using namespa...

2020-09-23 20:15:57 258

原创 认识多线程

#include<iostream>#include<thread>#include<mutex>//锁的头文件#include"cellTimestamp.h"using namespace std;mutex m;//锁const int ncount = 5;int sum = 0;CELLTimestamp cTime;void ...

2020-09-23 20:15:38 56

原创 多线程服务器

主要改进<server端>:主线程用于连接client端,开辟几个副线程去与client端接收数据和发送数据数据包格式没有改变#ifndef _MessageHeader_hpp_#define _MessageHeader_hpp_enum CMD{ CMD_LOGIN, CMD_LOGIN_RESULT, CMD_LOGOUT, CM...

2020-09-23 20:15:13 300

原创 内存池

内存池主要文件:MemoryMgr.h#ifndef _MemoeyMgr_hpp_#define _MemoeyMgr_hpp_#include<stdlib.h>#include<assert.h>#include<iostream>#define MAX_MEMORY_SIZE 128class MemoryAlloc;cla...

2020-09-23 20:14:25 105

原创 智能指针

#include<iostream>#include"Alloctor.h"#include<memory>//智能指针的库class A {public: A(){ Anum = 0; printf("A created\n"); } ~A(){ printf("A deleted\...

2020-09-23 20:13:39 74

原创 对象池

对象池头文件CELLObjectPool.h#ifndef _CELLObjectPool_hpp_#define _CELLObjectPool_hpp_#include<stdlib.h>#include<iostream>#include<mutex>#include<assert.h>using namespace std;...

2020-09-23 20:12:20 88

原创 自解锁

#include<iostream>#include<thread>#include<mutex>using namespace std;mutex m;const int ncount = 5;int sum = 0;CELLTimestamp cTime;//template<class _Mutex>//class ...

2020-05-01 12:04:17 264

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除