首页 > 编程知识 正文

atomicreference 详解,forrtl:severe(157) lsdyna

时间:2023-05-06 19:41:13 阅读:143331 作者:4832

今天写日志班,但是现在有错误。 不知道condition的destroy变成了什么样的死锁。 以前测试很好,但装入其他模块后就无法正常工作。 虽然必须想办法调试,但多线程程序很难调试。

首先让我们分析一下今天使用的这些函数。 其实以前见过libevent、muduo这些函数,但是因为学习了之后忘了,所以这次就总结一下。

1.valist C语言标准库头文件stdarg.h声明了一组用于增加参数的宏。 主要的是:

1、va_list用于声明表示参数表中每个参数的变量。

2、va_start初始化指向可变长度参数列表中第一个变量的指针.请注意,它只能出现在参数表的末尾。

3、每次调用va_arg时都会返回当前指针指向的变量,并将指针移动到下一个位置。 参数类型必须在此调用的第二个参数中指定。 va_arg也根据此参数确定偏移的距离。

4、va_end需要在函数末尾调用,进行一些清理工作。

示例:

# include iostream # include stdio.h # include string.h # include stdarg.hvoidprint (const char * format,) va _ list va char buf[1024]; memset(buf,0,sizeof ) buf ); vsprintf(buf,format,vlist ); printf(%s(n ),buf ); va_end(vlist ); }int main () { const char *s1='hello,'; const char *s2='world.'; 打印(' % s % s )、s1、s2 ); 返回0; }在本例中,可以输出' hello,world.'

2.snprintf

snprintf (),函数原型intsnprintf ) char*str,size_t size,const char *format,)。 根据format将可变数量的参数.格式化为字符串,并复制到str中

)1)如果字符串长度为size,则将此字符串全部复制到str,然后添加字符串终止符(((0) )。

)2)如果格式字符串的长度=size,则只将其中的(size-1 )字符复制到str,然后添加字符串终止符(“”)。 返回值是要写入的字符串的长度。

所以,valist和snprintf天生一对,是天衣无缝的合作。

3.vsnprintf和snprintf是c语言printf族函数的成员,相关函数列表如下:

# include stdio.hint printf (const char * format, //输出到标准输出int fprintf (file * stream,const char *format,); //输出到文件intsprintf (char * str,const char *format,); //输出到字符串str的intsnprintf(char*str,size_t size,const char *format,); 以下以size大小输出到字符串str的函数的功能与上面的一对一对应相同,但在函数调用时,将上面对应.的每个变量替换为va_list调用。 函数调用前的ap必须在va_start )宏中动态获取。 # include stdarg.hint vprintf (const char * format,va_list ap ); intvfprintf(file*stream,const char *format,va_list ap ); intvsprintf(char*str,const char *format,va_list ap ); intvsnprintf(char*str,size_t size,const char *format,va_list ap );

例如:通过vsnprintf ()实现snprintf ) )功能:

# include stdio.h # include stdarg.hint my _ snprintf (char * s,int size,const char *fmt,) /此自定义函数由系统提供int n=0; VA_start(AP,fmt ); //获取可变参数列表n=vsnprintf(s,size,fmt,ap ); //写入字符串sva_end(AP ); //释放资源return n返回写入的字符数(}int main ) { char str[1024]; my_snprintf(str,sizeof(str ),' %d,%d,%d,%d,%d ',5,6,7,8 ); printf(%s(n ),str ); 返回0; }

4.localtime函数返回gettimeofday(structtimeval*TV ),用于在localtime函数之前获取从1970年1月1日的0点到当前时间的时间戳, struct timezone *tz )函数。通常,如果只通过第一个参数tv获取秒和微秒的时间戳,将秒*1000*1000转换为微秒并加上微秒,则从1970年1月1日的零点开始到现在第二个参数用于存储时区,通常不使用。 struct timeval { time_t tv_sec; /* seconds */suseconds_t tv_usec; /* microseconds */}; gettimeoufday ()函数的一般用法: int64_t get_current_timestamp ) { structtimevalnow={ 0,0 }; gettimeofday(now,NULL ); return now.TV _ sec * 1000 * 1000 now.TV _ usec; }这样就成了时间戳。

与localtime函数组合,变换为人类可读的时间格式如下所示。

# include iostream # include time.h # includesys/time.husingnamespacestd; int main () structtimevalnow=) 0,0 ); gettimeofday(now,NULL ); time_t t=now.tv_sec; sructTM*sys_TM=localtime(t; struct tm my_tm=*sys_tm; 返回0; }

可以在GDB上看到:

5.strchr ) )函数:查找某个字符在字符串中最后一次出现的位置,例如“./path”。 这样,就会回到“/”所在位置的下标p。 我们使用p 1可以到达path名称。

6.fstream按以下方式打开文件,以检测是否真的打开了文件:

请注意,要使用fstream,必须包括头文件#include fstream。 只有iostream不可用。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。