摘要: 注:本文仅针对Cortex-M3/4 系列进行讲述。 在传统的ARM处理器架构中,常使用SWP指令来实现锁的读/写原子操作,但从ARM v6开始,读/写访问在独立的两条总线上进行,SWP指令已无法在此架构下保证读/写访问的原子操作,因此互斥访问指令应运而生。本文结合项目中运用的相关方法,总结Cort 阅读全文
posted @ 2019-04-22 15:10 ba哥 阅读(3475) 评论(0) 推荐(1) 编辑
摘要: 一个具体的场景:在多线程中,当一个线程获得锁之后异常退出后,应该怎么处理? 方案一 使用锁的robust特性 简单地讲,就是当拥有这个锁的线程挂了后,下一个尝试去获得锁的线程会得到EOWNWERDEAD的返回值,新的拥有者应该再去调用pthread_mutex_consistent_np()来保持锁 阅读全文
posted @ 2019-08-05 11:19 ba哥 阅读(1801) 评论(0) 推荐(0) 编辑
摘要: 这是一道机试题,大概的预期执行结果如下图所示 最近刚好在学习linux编程,便使用多线程及多进程分别实现了一遍,其中多线程较为简单,使用0/1信号量在线程间实现生产者/消费者即可;多进程则稍微复杂一些,信号量必须设置为进程间通信,且存放在共享内存中,才能被多个进程访问。 多线程的实现代码如下: 多进 阅读全文
posted @ 2019-07-09 17:28 ba哥 阅读(1269) 评论(0) 推荐(0) 编辑
摘要: Introduction to Linux Threads A thread of execution is often regarded as the smallest unit of processing that a scheduler works on. A process can have 阅读全文
posted @ 2019-07-09 17:07 ba哥 阅读(237) 评论(0) 推荐(0) 编辑
摘要: Mutual exclusion means that only a single thread should be able to access the shared resource at any given point of time. This avoids the race conditi 阅读全文
posted @ 2019-07-02 17:13 ba哥 阅读(757) 评论(0) 推荐(0) 编辑
摘要: 以一段简单的函数调用开始,看看程序的上下文是如何切换的。 工具:Keil5 平台:Cortex-M7 1. 简单函数调用 编译成功后仿真,看看汇编里做了啥: 1. 程序执行到C代码的17行 时调用子函数,准备切换下文,首先将func()的传参从右向左扫描,依次暂存在寄存器中(见下列汇编 1-7行)。 阅读全文
posted @ 2019-06-25 22:27 ba哥 阅读(2017) 评论(0) 推荐(0) 编辑
摘要: Shared Memory Shared memory is a memory shared between two or more processes. However, why do we need to share memory or some other means of communica 阅读全文
posted @ 2019-06-24 15:59 ba哥 阅读(529) 评论(0) 推荐(0) 编辑
摘要: Semaphores are a programming construct designed by E. W. Dijkstra in the late 1960s. Dijkstra's model was the operation of railroads: consider a stret 阅读全文
posted @ 2019-06-24 15:58 ba哥 阅读(276) 评论(0) 推荐(0) 编辑
摘要: Unreliable Guide To Locking Introduction Welcome, to Rusty’s Remarkably Unreliable Guide to Kernel Locking issues. This document describes the locking 阅读全文
posted @ 2019-06-24 15:57 ba哥 阅读(334) 评论(0) 推荐(0) 编辑
摘要: Linux Signals Fundamentals – Part I Linux Signals Fundamentals – Part I What is a signal? Signals are software interrupts. A robust program need to ha 阅读全文
posted @ 2019-06-24 15:56 ba哥 阅读(771) 评论(0) 推荐(0) 编辑
摘要: The client server model Most interprocess communication uses the client server model. These terms refer to the two processes which will be communicati 阅读全文
posted @ 2019-06-24 15:47 ba哥 阅读(494) 评论(0) 推荐(0) 编辑