Linux
文章平均质量分 65
sunnyyouknow
这个作者很懒,什么都没留下…
展开
-
linux-多线程
From: http://blog.csdn.net/lanyan822/article/details/7586845 线程的创建 使用pthread_create函数。 #include int pthread_create (pthread_t *__restrict __newthread,//新创建的线程ID转载 2013-08-09 11:36:53 · 371 阅读 · 0 评论 -
条件变量
http://blog.csdn.net/lanyan822/article/details/7586845 条件变量用pthread_cond_t数据类型表示。 条件变量本身由互斥量保护,所以在改变条件状态前必须锁住互斥量。 条件变量初始化: 第一种,赋值常量PTHREAD_COND_INITIALIZER;第二种,使用pthread_cond_init函数 int转载 2013-08-09 11:27:30 · 365 阅读 · 0 评论 -
轮询方式实现线程间共享变量
#include #include #include int flag = 1; void *thread_function(void *arg); int main() { int res; pthread_t a_thread; void *thread_result; int count = 1; res = pthread_create原创 2013-08-10 11:51:47 · 486 阅读 · 0 评论 -
使用互斥量实现线程间同步
#include #include #include #include #include #define SIZE 1024 char buffer[SIZE]; void *thread_function(void *arg); pthread_mutex_t mutex; int main() { int res; pthread_t a_thread;原创 2013-08-10 12:31:24 · 692 阅读 · 0 评论 -
使用信号量实现线程间同步
#include #include #include #include #include #define SIZE 1024 void *thread_function(void *arg); char buffer[SIZE]; sem_t sem; int main() { int res; pthread_t a_thread; void *thre原创 2013-08-10 12:25:44 · 666 阅读 · 0 评论 -
取消一个线程
#include #include #include void *thread_function(void *arg); int main() { int res; pthread_t a_thread; void *thread_result; res = pthread_create(&a_thread, NULL, thread_function,原创 2013-08-10 23:14:24 · 394 阅读 · 0 评论 -
简单多线程
#include #include #include #define NUM 6 void *thread_function(void *arg); int main() { int res; pthread_t a_thread[NUM]; void *thread_result; int index; for (index = 0; ind原创 2013-08-10 23:26:41 · 383 阅读 · 0 评论 -
linux异步IO
linux下主要有两套异步IO,一套是由glibc实现的(以下称之为glibc版本)、一套是由linux内核实现,并由libaio来封装调用接口(以下称之为linux版本)。 比较 从上面的流程可以看出,linux版本的异步IO实际上只是利用了CPU和IO设备可以异步工作的特性(IO请求提交的过程主要还是在调用者线程上同步完成的,请求提交后由于CPU与IO设备可以并行工作,所以调用流程原创 2013-08-28 17:42:18 · 483 阅读 · 0 评论 -
简单的echo服务器程序
#include #include #include #include #include #include #include #include #define SERVERIP "192.168.1.193" #define SERVERPORT 12345 #define MAXBUFFER 256 int main(int argc, char** argv) { i转载 2013-08-29 11:57:00 · 815 阅读 · 0 评论