pthread

Linux多线程基本函数

久未见 提交于 2019-11-26 17:55:03
按照所学的进度会不断更新...虽然学的可能有点慢 1、pthread_create():创建线程 头文件:#include<pthread.h> 函数声明: int pthread_create(pthread_t *restrict tidp, //新创建的线程ID指向的内存单元           const pthread_attr_t *restrict_attr, //设置线程属性,默认为NULL           void*(*start_rtn)(void*), //新创建的线程从start_rtn函数的地址开始运行           void *restrict arg);//默认为NULL,若上述函数需要参数,将参数放入结构中并将地址作为arg传入 返回值:若创建成功返回0,否则返回出错编号 来源: https://www.cnblogs.com/z1014601153/p/11329823.html

ffmpeg的hevc slice多线程解码

柔情痞子 提交于 2019-11-26 17:09:29
ff_thread_init判断对slice并行或者frame并行进行初始化 int ff_thread_init(AVCodecContext *avctx) 71 { 72 validate_thread_parameters(avctx); 73 74 if (avctx->active_thread_type&FF_THREAD_SLICE) 75 return ff_slice_thread_init(avctx); 76 else if (avctx->active_thread_type&FF_THREAD_FRAME) 77 return ff_frame_thread_init(avctx); 78 79 return 0; 80 } ff_slice_thread_init是帧级并行初始化 int ff_slice_thread_init(AVCodecContext *avctx) 130 { 131 SliceThreadContext *c; 132 int thread_count = avctx->thread_count; 133 static void (*mainfunc)(void *); 134 135 // We cannot do this in the encoder init as the threads are created

条件变量与互斥量(2)

允我心安 提交于 2019-11-26 05:21:30
因为线程的代码基本没怎么写过,leet-code出了线程题,刷下。 1116. 打印零与奇偶数 假设有这么一个类: class ZeroEvenOdd { public ZeroEvenOdd(int n) { ... } // 构造函数 public void zero(printNumber) { ... } // 仅打印出 0 public void even(printNumber) { ... } // 仅打印出 偶数 public void odd(printNumber) { ... } // 仅打印出 奇数 } 相同的一个 ZeroEvenOdd 类实例将会传递给三个不同的线程: 线程 A 将调用 zero(),它只输出 0 。 线程 B 将调用 even(),它只输出偶数。 线程 C 将调用 odd(),它只输出奇数。 每个线程都有一个 printNumber 方法来输出一个整数。请修改给出的代码以输出整数序列 010203040506... ,其中序列的长度必须为 2n。 示例 1: 输入:n = 2 输出:"0102" 说明:三条线程异步执行,其中一个调用 zero(),另一个线程调用 even(),最后一个线程调用odd()。正确的输出为 "0102"。 示例 2: 输入:n = 5 输出:"0102030405" VERSION 1:   三锁版

打通用户态程序和内核系列之二:pthread_mutex_lock的实现

我怕爱的太早我们不能终老 提交于 2019-11-25 21:55:56
一个很容混淆的地方是,误以为用户程序锁API的实现和接口,最终也会调用内核相关的锁操作提供的API。 应用程序锁API接口 主要的API有: pthread_mutex_lock; 相关说明如下: NAME pthread_mutex_lock -- lock a mutex SYNOPSIS #include <pthread.h> int pthread_mutex_lock(pthread_mutex_t *mutex); DESCRIPTION The pthread_mutex_lock() function locks mutex. If the mutex is already locked, the calling thread will block until the mutex becomes available. RETURN VALUES If successful, pthread_mutex_lock() will return zero, otherwise an error number will be returned to indicate the error. ERRORS The pthread_mutex_lock() function will fail if: [EINVAL] The value specified by mutex