
C语言
lichao268089
这个作者很懒,什么都没留下…
展开
-
C/C++移植IOS(CMAKE编译与链接)
C/C++移植IOS(CMAKE编译与链接)原创 2022-06-18 14:16:07 · 511 阅读 · 0 评论 -
system函数详解
system函数详解原创 2020-02-24 14:06:59 · 222 阅读 · 0 评论 -
文件结构体struct stat介绍
文件结构体struct stat介绍原创 2019-10-19 17:02:32 · 320 阅读 · 0 评论 -
多线程的pthread_exit函数
pthread_exit(void*)用于线程的退出函数,不会导致主进程退出,int main 中的return 语句会导致进程退出;1 #include <pthread.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <unistd.h> 5 6 void* thread_func...原创 2019-04-20 15:16:52 · 1550 阅读 · 0 评论 -
线程函数pthread_join
pthread_join函数用于回收子线程,并且可以获取到子线程的退出状态; 1 #include <stdio.h> 2 #include <string.h> 3 #include <unistd.h> 4 #include <pthread.h> 5 6 &...原创 2019-04-20 16:48:02 · 245 阅读 · 0 评论 -
C语言函数返回值--局部变量和局部变量地址
返回局部变量地址转载 2019-04-25 11:34:11 · 708 阅读 · 0 评论 -
memove函数及 memcpy实现
memmove函数原型:void* memmove(void* dest;const void* src,size_t n){assert((dest != 0)&&(src != 0));char* p_dest = (char*) dest;char* p_src = (char*) src;int i = 0;if( (p_dest < p_src) ||...转载 2019-05-08 12:02:56 · 285 阅读 · 0 评论 -
Qt解析xml方法
qt解析xml方法转载 2019-04-30 14:51:13 · 318 阅读 · 0 评论 -
Linux sudo命令详解
Linux sudo命令详解](https://blog.youkuaiyun.com/yongchaocsdn/article/details/78680085)转载 2019-06-04 16:42:29 · 410 阅读 · 0 评论 -
gdb调试命令的使用及总结
gdb调试命令的使用及总结转载 2019-06-04 17:55:50 · 654 阅读 · 0 评论 -
C语言中多线程数据共享问题
C语言中多线程之间共享全局变量data段数据实例(和多进程之间相反,多进程之间的全局变量不共享,每一个进程有独自的0到4G的地址空间) 2 #include <string.h> 3 #include <unistd.h> 4 #include <pthread.h> 5 6 7 8 int var = 100; 9 ...原创 2019-04-20 14:39:20 · 5161 阅读 · 0 评论 -
线程同步-生产者消费者条件变量模型
线程同步典型案例为生产者消费者模型,而借助条件变量来实现这一模型,时比较常见的一种做法。假定有2个线程,一个模拟生产者行为,一个模拟消费者行为。两个线程同时操作一个共享资源(一般称之为汇聚),生产者向其中添加产品,消费者从中消费掉产品;看如下实例,使用条件变量模拟生产者,消费者问题:...原创 2019-04-24 00:11:17 · 195 阅读 · 0 评论 -
线程同步-条件变量
条件变量条件变量本身不是锁!但它可以造成线程阻塞。通常与互斥锁配合使用,给多线程提供一个会和的场所;主要应用函数:pthread_cond_init函数;pthread_cond_destroy函数;pthread_cond_wait函数;pthread_cond_timedwait函数;pthread_cond_signal函数;pthread_cond_broadcast函数;...原创 2019-04-23 23:34:19 · 142 阅读 · 0 评论 -
多线程pthread_cancel函数
pthread_cancel(pthread_t tid)杀死一个线程,对应进程中的kill函数;成功返回0,失败返回错误码;注意:线程的取消并不是实时的,需要一个取消点,而这个取消点一般是一个系统调用函数,如果线程之中没有这个取消点,可以调用pthread_testcancel函数自行设置一个取消点;` 1 #include <stdio.h> 2 #include <...原创 2019-04-20 18:16:10 · 1163 阅读 · 0 评论 -
进程和线程的对比
fork pthread_createexit(10)(进程退出) pthread_exit(,void**)wai(int*)(回收子进程,进程没结束会阻塞等待) pthread_join(回收子线 ...原创 2019-04-21 14:14:45 · 259 阅读 · 0 评论 -
二级指针作为传出参数
二级指针作为传出参数不能直接如下定义:void** ret; 1 #include <pthread.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <unistd.h> 5 #include <stdlib.h> 6 void* thread_f...原创 2019-04-21 16:26:53 · 461 阅读 · 0 评论 -
线程同步的方法
线程同步概念:线程按照先后次序运行;线程同步指一个线程发出某一功能调用时,在没有得到结果之前,该调用不返回。同时其他线程为保证数据的一致性,不能调用该功能;需要线程同步的原因:1.数据共享;2.线程之间竞争;3.多个对象没有合理的同步机制;(前2点不能改变,因此只能修改第三点)互斥量(互斥锁):锁不具有强制性(建议锁)读写锁:条件变量:信号量:进程间同步:1.信号量;2.文件锁,r...原创 2019-04-21 18:04:19 · 121 阅读 · 0 评论 -
线程同步方法-信号量
可以理解为进化版的互斥锁(1->N)由于互斥锁的粒度比较大,如果我们希望在多个线程间对某一对象的部分数据进行共享,使用互斥锁是没有办法实现的,只能将整个数据对象锁住,这样虽然达到了多线程操作共享数据时保证数据正确性的目的,却无形中导致线程的并发行降低。线程并行执行,变成了串行执行,与直接使用单进程没有区别,信号量是相对折中的一种做法,既能保证同步,数据不混乱,又能提高线程并发;(注意:进程...原创 2019-04-25 23:44:01 · 629 阅读 · 0 评论 -
linux信号机制
linux信号机制转载 2019-04-22 10:39:02 · 130 阅读 · 0 评论 -
extern "C"作用
extern"C"作用转载 2019-04-22 17:43:01 · 107 阅读 · 0 评论 -
线程同步中的死锁现象
出现死锁的情况:1. 线程出现对同一个互斥量A加锁两次;2.线程1拥有A锁,请求获取B锁;线程2拥有B锁,请求获取A锁;第一种情况实例代码: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <pthread.h> 5 #inc...原创 2019-04-22 22:43:15 · 332 阅读 · 0 评论 -
线程同步方法-读写锁
读写锁:与互斥锁(互斥量相似)但性能更高一些;其特性为:写独占,读共享;读写锁状态:一把锁具有三种状态:1.读模式下的锁状态(读锁);2.写模式下的锁状态(写锁);3不加锁;读写锁特点:写独占,读共享,写锁优先级高;1.读写锁是以“写模式加锁”时,解锁前,所有对该锁加锁的线程都会被阻塞;2.读写锁是以“读模式加锁”时,如果剩下所有线程都以读模式对其加锁会成功,如果线程中有写模式,则...原创 2019-04-23 00:03:24 · 225 阅读 · 0 评论 -
线程分离函数pthread_detach
pthread_detach函数实现线程分离,无系统残留资源(服务器,网络经常使用) 1 #include <stdio.h> 2 #include <string.h> 3 #include <pthread.h> 4 5 6 void* tnf(void* arg) 7 { 8 int n = 3; 9 ...原创 2019-04-20 17:22:40 · 1112 阅读 · 0 评论