文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | firefox | WPS | 杀毒软件 | Picasa
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形图像 办公软件 媒体动画 精文荟萃 常用软件 网页编程 技术开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院程序开发C/C++进程和线程编程
精品推荐
特别推荐
·C语言编程易犯毛病集合
·C语言编程常见问题解答(目录)
·C#程序开发中的常用函数汇总
·C#数据库操作的三种经典用法
·C/C++笔试、面试题目大汇总
·Beej的网络socket编程指南
·socket编程原理
·C语言的常用库函数使用方法分析及用途
·在C语言中如何处理时间和日期
·C++设计模式之Singleton
·VC++动态链接库编程之MFC扩展 DLL
·TCP/IP网络重复型服务器通信软件的设计
·DirectX游戏开发入门
·经典与现代的结合:在MFC中集成RAD .NET框架
·Windows API-GDI入门基础知识详解(2)
·Visual C++ 入门精解
·C#基础概念二十五问
·用C#实现pdf文件的完整性验证
·成为嵌入式程序员应知道的0x10个问题
·TCP/IP编程实现远程文件传输
热点TOP10
·C#编写的windows计算器-源代码
·socket编程原理
·TCP/IP编程实现远程文件传输
·C#基础概念二十五问
·Beej的网络socket编程指南
·C/C++笔试、面试题目大汇总
·如何用C#编写文本编辑器
·C#源码读取excel数据到程序中-SQL SERVER-到dataset中
·飞机订票系统设计
·C# GridView 排序及分页
·C语言图形函数
·学生成绩管理系统实习
·DirectX游戏开发入门
·Windows下C语言网络编程快速入门
·扑克牌的发牌程序(用伪随机数实现)
·C语言编程常见问题解答(目录)
·c#的random shuffle
·用C#下的Raw Socket编程实现网络封包监视
·进程调度模拟程序
·Visual C++ 实现数字化图像的分割

进程和线程编程

日期:2008年4月7日 作者: 查看:[大字体 中字体 小字体]


Semaphore.h

#ifndef SEMAPHORES
#define SEMAPHORES
#include
#include
typedef struct Semaphore
{
int v;
pthread_mutex_t mutex;
pthread_cond_t cond;
}
S e m a p h o r e ;
int semaphore_down (Semaphore * s);
int semaphore_decrement (Semaphore * s);
int semaphore_up (Semaphore * s);
void semaphore_destroy (Semaphore * s);
void semaphore_init (Semaphore * s);
int semaphore_value (Semaphore * s);
int tw_pthread_cond_signal (pthread_cond_t * c);
int tw_pthread_cond_wait (pthread_cond_t * c, pthread_mutex_t * m);
int tw_pthread_mutex_unlock (pthread_mutex_t * m);
int tw_pthread_mutex_lock (pthread_mutex_t * m);
void do_error (char *msg);
# e n d i f

Semaphore.c

#include "semaphore.h"
/ *
* function must be called prior to semaphore use.
*
* /
v o i d
semaphore_init (Semaphore * s)
{
s->v = 1;
if (pthread_mutex_init (&(s->mutex), pthread_mutexattr_default) == -1)
do_error ("Error setting up semaphore mutex");
if (pthread_cond_init (&(s->cond), pthread_condattr_default) == -1)
do_error ("Error setting up semaphore condition signal");
* function should be called when there is no longer a need for
* the semaphore.
*
* /
v o i d
semaphore_destroy (Semaphore * s)
{
if (pthread_mutex_destroy (&(s->mutex)) == -1)
do_error ("Error destroying semaphore mutex");
if (pthread_cond_destroy (&(s->cond)) == -1)
do_error ("Error destroying semaphore condition signal");
}
/ *
* function increments the semaphore and signals any threads that
* are blocked waiting a change in the semaphore.
*
* /
i n t
semaphore_up (Semaphore * s)
{
int value_after_op;
tw_pthread_mutex_lock (&(s->mutex));
( s - > v ) + + ;
value_after_op = s->v;
tw_pthread_mutex_unlock (&(s->mutex));
tw_pthread_cond_signal (&(s->cond));
return (value_after_op);
}
/ *
* function decrements the semaphore and blocks if the semaphore is
* <= 0 until another thread signals a change.
*
* /
i n t
semaphore_down (Semaphore * s)
{
int value_after_op;
tw_pthread_mutex_lock (&(s->mutex));
while (s->v <= 0)
{
tw_pthread_cond_wait (&(s->cond), &(s->mutex));
}
( s - > v ) - - ;
value_after_op = s->v;
tw_pthread_mutex_unlock (&(s->mutex));
return (value_after_op);
}
/ *
* function does NOT block but simply decrements the semaphore.
* should not be used instead of down -- only for programs where
* multiple threads must up on a semaphore before another thread
* can go down, i.e., allows programmer to set the semaphore to
* a negative value prior to using it for synchronization.
*
* /
i n t
semaphore_decrement (Semaphore * s)
{
int value_after_op;
tw_pthread_mutex_lock (&(s->mutex));
s - > v - - ;
value_after_op = s->v;

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] 下一页 




上一篇:如何实现大图标风格的打开对话框

下一篇:ar和nm命令的使用

进程和线程编程 相关文章:
·Windows系统进程列表完全解析
·windows 2000进程一览
·进程调度模拟程序
·识别非法进程及手工杀毒技巧
·notepad - notepad.exe - 进程信息
·进程和线程编程
·无进程DLL木马开发思路与实现
·详细讲解Linux操作系统的进程管理的功能
·windows进程中的内存结构
·操作系统学习:认识 Rundll32.exe 进程
进程和线程编程 相关软件:
·进程管理王 V1.35 绿色版
·ECQ (进程浏览器) V6.0 绿色版
·UNIX网络编程 第2版 第2卷 进程间通信
·Windows进程管理器 V4.01
·进程执法官V1.50 个人版
·进程端口关联监视工具 3.02
·列举进程DELPHI教程
·进程杀手V1.04 增强版
·进程间谍V1.1.1.0
·进程猎人V3.2

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.viphot.com
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.viphot.com All Rights Reserved. 鄂ICP备05000083号Powered by:vipcn