c++写日志 线程安全

#include <iostream>
#include <thread>

#include "Abnormality.h"

int _stdcall video_work(void*arg)
{
	FILE *fp = (FILE *)arg;
	int index = 100;
	while (index--)
	{
		bugs(fp," i=%d\n", index);
	}

	return 0;
}


int main()
{
	FILE *fp = NULL;
	fopen_s(&fp, f_PATH_TYPE);

	void * index = nullptr;
	int length = 100;
	for (size_t i = 0; i < length; i++)
	{
		index = &i;
		std::thread th(video_work, fp);
		th.detach();
	}

	fclose(fp), fp = NULL;

    std::cout << "Hello World!\n";
}
#ifndef _ABNORMALITY_H_
#define _ABNORMALITY_H_

#ifdef __cplusplus
/** Macro to start a block of C symbols */
#  define _C_START_           extern "C" {
/** Macro to end a block of C symbols */
#  define _C_END_             }
#else
#  define _C_START_
#  define _C_END_
#endif

#define __DLL___
#ifdef	__DLL___
#define DLL_  __declspec(dllexport)
#else
#define DLL_ __declspec(dllimport)
#endif



#define f_PATH_TYPE			"log_info.log", "a+"

#define FFL					__FUNCTION__, __LINE__
#define FFLDT				FFL, __DATE__, __TIME__
#define FFL_X				__FILE__, FFLDT

/** 本地文件写debug */
#define bugs(fp,s, ...)  	fprintf(fp, "%s()#%d %s %s" s, FFLDT, ##__VA_ARGS__);

/** 本地文件写error */
#define log(fp,s)				fprintf(fp, "%s()#%d %s %s %s\n", FFLDT,s); 

#define logfsx(fp,s, ...)		fprintf(fp, "%s %s()#%d %s %s\n"s, FFL_X, ##__VA_ARGS__); 


_C_START_



_C_END_

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

资深码农

让我们和小姐姐唠嗑可以肢愣起来

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值