pthreads

Disable __thread support

蹲街弑〆低调 提交于 2020-12-29 20:56:28
问题 I'm implementing a pthread replacement library which is extremely lightweight. There are several reasons why I want to disable __thread completely. It's a waste of memory. If I'm creating a thousand threads which has nothing to do with the context that declares a variable with __thread they will still allocate the program will still have allocated 1000*the size of that data bytes and never use it. It's simply not memory compatible with the mass-concurrency model. If we need extremely

Pointer passed to function changes unexpectedly

萝らか妹 提交于 2020-12-27 06:35:02
问题 I'm designing a preloader-based lock tracing utility that attaches to Pthreads, and I've run into a weird issue. The program works by providing wrappers that replace relevant Pthreads functions at runtime; these do some logging, and then pass the args to the real Pthreads function to do the work. They do not modify the arguments passed to them, obviously. However, when testing, I discovered that the condition variable pointer passed to my pthread_cond_wait() wrapper does not match the one

Pointer passed to function changes unexpectedly

老子叫甜甜 提交于 2020-12-27 06:34:58
问题 I'm designing a preloader-based lock tracing utility that attaches to Pthreads, and I've run into a weird issue. The program works by providing wrappers that replace relevant Pthreads functions at runtime; these do some logging, and then pass the args to the real Pthreads function to do the work. They do not modify the arguments passed to them, obviously. However, when testing, I discovered that the condition variable pointer passed to my pthread_cond_wait() wrapper does not match the one

Pointer passed to function changes unexpectedly

只愿长相守 提交于 2020-12-27 06:34:46
问题 I'm designing a preloader-based lock tracing utility that attaches to Pthreads, and I've run into a weird issue. The program works by providing wrappers that replace relevant Pthreads functions at runtime; these do some logging, and then pass the args to the real Pthreads function to do the work. They do not modify the arguments passed to them, obviously. However, when testing, I discovered that the condition variable pointer passed to my pthread_cond_wait() wrapper does not match the one

Error using pthread on Windows with Mingw

◇◆丶佛笑我妖孽 提交于 2020-12-27 06:08:51
问题 I'm trying to use threads on a Windows C program, compiled on an Eclipse environment and Mingw. I've also put -lpthread and -pthread on the compilation command, and included on the program. I made calls to pthread_create(), pthread_cancel() and pthread_exit() where appropriate on my logic. It always works as intended, but that my program ends saying This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

Error using pthread on Windows with Mingw

别等时光非礼了梦想. 提交于 2020-12-27 06:06:30
问题 I'm trying to use threads on a Windows C program, compiled on an Eclipse environment and Mingw. I've also put -lpthread and -pthread on the compilation command, and included on the program. I made calls to pthread_create(), pthread_cancel() and pthread_exit() where appropriate on my logic. It always works as intended, but that my program ends saying This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

Linux not respecting SCHED_FIFO priority ? ( normal or GDB execution )

旧时模样 提交于 2020-12-26 19:01:51
问题 TL;DR On multiprocessors/multicores engines, more than one RT SCHED_FIFO threads may be scheduled on more than one execution unit. So thread with priority 60 and thread with priority 40 may run simultaneously on 2 different cores. This may be counter-intuitive, especially when simulating embedded systems that (often as today) run on single core processors and rely on strict priority execution. See my other answer in this post for summary Original problem description I have difficulties even

Linux not respecting SCHED_FIFO priority ? ( normal or GDB execution )

China☆狼群 提交于 2020-12-26 19:01:48
问题 TL;DR On multiprocessors/multicores engines, more than one RT SCHED_FIFO threads may be scheduled on more than one execution unit. So thread with priority 60 and thread with priority 40 may run simultaneously on 2 different cores. This may be counter-intuitive, especially when simulating embedded systems that (often as today) run on single core processors and rely on strict priority execution. See my other answer in this post for summary Original problem description I have difficulties even

用信号量机制解决生产者消费者问题

南笙酒味 提交于 2020-12-14 09:15:33
使用POSIX标准中的Pthreads API来创建多个生产者、消费者线程 定义线程:pthread_t tid 创建线程:pthread_create(&tid,&attr,runner,argv[1]); join线程:pthread_join(tid,NULL); 使用PthreadsAPI的信号量机制互斥与同步 定义信号量:sem_t sem 初始化信号量:sem_init(&sem, 0, n); P操作:sem_wait(&sem); V操作:sem_post(&sem); #include <stdio.h> #include <pthread.h> #include <semaphore.h> #define BUFF_SIZE 5 // 定义缓冲区buffer大小为5 int buffer[BUFF_SIZE]; // 用循环队列模拟缓冲区 int in = 0; // 产品进缓冲区时的缓冲区下标 int out = 0; // 产品出缓冲区时的缓冲区下标 int productID = 0; // 产品号 int consumeID = 0; // 将被消耗的产品号 sem_t s; // 定义互斥信号量, 互斥锁s sem_t n; // 定义同步信号量n, buffer中已放入的产品个数 sem_t e; // 定义同步信号量e, buffer中空单元个数

Linux进程状态查询

僤鯓⒐⒋嵵緔 提交于 2020-12-04 08:15:18
进程状态详细说明 Linux进程状态详细解析 ps 的参数说明 ps 提供了很多的选项参数,常用的有以下几个: l 长格式输出; u 按用户名和启动时间的顺序来显示进程; j 用任务格式来显示进程; f 用树形格式来显示进程; a 显示所有用户的所有进程(包括其它用户); x 显示无控制终端的进程; r 显示运行中的进程; ww 避免详细参数被截断; 我们常用的选项是组合是 aux 或 lax,还有参数 f 的应用。 ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 3532 0.0 0.2 2428 452 ? Ss 20:40 0:00 gpm -m /dev/input/mice -t imps2 htt 3564 0.0 1.7 29460 3704 ? Sl 20:41 0:00 htt_server -nodaemon root 3574 0.0 0.4 5236 992 ? Ss 20:41 0:00 crond root 3627 0.0 0.2 3448 552 ? SNs 20:41 0:00 anacron -s root 3636 0.0 0.1 2304 420 ? Ss 20:41 0:00 /usr/sbin/atd ubuntu2 3655 0.0 0.5 13840