易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux操作系统下的多线程编程详细解析(4)


   函数原型:
   
#include <pthread.h>
void pthread_cleanup_push(void (*rtn)(void *),void *arg);
    函数rtn是清理函数,arg是调用参数
void pthread_cleanup_pop(int execute);
 
 
    在前面讲过线程的终止方式,是正常终止还是非正常终止,都会存在一个资源释放的问题,在posix中提供了一组,就是我们上面看的函数进行线程退出的处理函数,有些像在进程中的atexit函数。释放的方式是指pthread_cleanup_push的调用点到pthread_cleanup_pop之间程序段进行终止。
    pthread_cleanup_push()/pthread_cleanup_pop采用先入后出的方式的栈的管理方式,void *rtn(void *),在执行pthread_cleanup_push()时压入函数栈,多次执行pthread_cleanup_push()形成一个函数链,在执行这个函数链的时候会以反方向弹出,即先入后出。execute参数表识,是否执行弹出清理函数,当execute=0时不进行弹出清理函数,非零的时候弹出处理函数。
    例程9
    程序目的:实现在正常结束线程的时候,进行函数处理
    程序名称:pthread_clean.c
 /********************************************************************************************
**    Name:pthread_clean.c
**    Used to study the multithread programming in Linux OS
**    A example showing a thread to be cleaned.
**    Author:zeickey
**    Date:2008/6/28       
**    Copyright (c) 2006,All Rights Reserved!
*********************************************************************************************/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *clean(void *arg)
{
    printf("cleanup :%s  \n",(char *)arg);
    return (void *)0;
}
void *thr_fn1(void *arg)
{
    printf("thread 1 start  \n");
    pthread_cleanup_push( (void*)clean,"thread 1 first handler");
    pthread_cleanup_push( (void*)clean,"thread


相关文档:

linux设备驱动程序——网络设备驱动程序

Linux的网络系统主要是基于BSD Unix 的socket机制, 访问网络设备的驱动程序不需要使用设备节点。在系统和驱动程序之间定义有专门的数据结构(sk_buff)进行数据的传递。系统内部支持对发送数据和接收数据的缓存,提供流量控制机制,提供对多协议的支持。因此,选择哪个驱动程序是基于内核内部的其他决定,而不是调用open() ......

Linux 2.6下SPI设备模型


Linux 2.6下SPI设备模型
--------基于AT91RM9200分析
       Atmel公司的ARM AT系列,其SPI驱动在kernel 2.6.23里已经包含。如果你打了at91-patch补丁的话,则在内核配置时要小心。在Device Drivers---- > Character devices ---- >取消选中SPI Driver(legacy) for at91rm9200 pro ......

Linux系统dameon程序的core dump设置

To enable dumps for every daemon:

ulimit -c unlimited >/dev/null 2>&1 (-c maximum size of core files)
ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1

Dump for system
:
DAEMON_COREFILE_LIMIT='unlimited'

The same for every daemon (in /etc/sysconfig/_daemon_ ......

linux c oci 远程连接例子

以下是我的测试oci的例子!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oci.h"
static OCIServer        *srvhp;
static OCISession       *p_session;
static OCIEnv    &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号