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
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
/home
作为文件服务器等多用户系统使用时,建议设置于单独分区中。这样当发布的系统需要升级时,或者重装系统时显得尤其便利。
/var
此目录中存放log等时常更新的文件,像syslog这样的文件容量很大,有超出文件系统容量的可能。建议设置于单独的分区中。
/usr
仅在添加新程序时会改变其中的内容,建议设置为只读 ......
嵌入式Linux下彩色LCD驱动的设计与实现
摘要:本文介绍了如何在嵌入在开发彩色LCD显示驱动的方法,并对Linux中的显示驱动程序结构和框架作一介绍。
长期以来,在常见的掌上电脑(PDA)等小型手持式设备上,由于硬件条件等的限制,我们看到的显示器件通常是单色LCD,用户界面也非常简单,几乎看不到 PC ......
今天发现很多程序死在linux 服务进中
问个问题 今天发现很多程序死在linux 服务进中
已经死了好多天了。用crontab 都定在 凌晨0点跑。
想知道如何查看 服务器哪方面的资源太少导致进程死在里面?
ps -ef|grep load/script | awk '{print $2}' 把死进程的 ID 打印出来
......
Here is small script that does this. Debian or Ubuntu GNU/Linux does
not comes with any SYS V init script (located in /etc/init.d directory)
.
You create a script as follows and use it to stop or flush the iptables rules.
Please don't type rules at command prompt. Use the script to sp ......