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

Linux 多线程编程

linux 多线程编程非常简单。
一、多线程编程的流程:
创建线程--->当前线程继续工作--->[与创建的线程同步]--->[等待创建的线程结束与返回]--->当前线程继续工作。
            --->创建的线程开始工作--->[与别的线程同步]--->退出线程并返回     
线程用的几个主要的函数。
1.线程创建函数:pthread_create(pthread_t * id,pthread_attr_t *attr,void *(*start_routine)(void*),void *arg);
   id---线程id ,线程创建成功时的返回值,用于对线程的操作。
   attr---线程属性,简单的设为NULL就可以了。
   void *(*start_routine)(void*) --- 线程函数,也就工作线程的实际运行部分的代码段。
   arg --- 线程参数,是双向的,也就是一个输入输出类型的参数。
2.等待线程返回函数:pthread_join(pthread_t id,void *ret);
   id--- 线程id。
   ret --- 线程的返回值。
3.退出线程:pthread_exit(void *ret);
   ret --- 线程返回值。
一个简单的线程的例子:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
void *thread_function(void *arg);
char message[] = "Hello World";
int main() {
    int res;
    pthread_t a_thread;
    void *thread_result;
    res = pthread_create(&a_thread, NULL, thread_function, (void *)message);
    if (res != 0) {
        perror("Thread creation failed");
        exit(EXIT_FAILURE);
    }
    printf("Waiting for thread to finish...\n");
    res = pthread_join(a_thread, &thread_result);
    if (res != 0) {
        perror("Thread join failed");
        exit(EXIT_FAILURE);
    }
    printf("Thread joined, it returned %s\n", (char *)thr


相关文档:

一个linux 混音播放的 /etc/asound.conf 配置

备用。
只有相同用户才能实现设备的同时打开。
pcm.!dmix {
type dmix
ipc_key 5678293
ipc_key_add_uid yes
slave {
pcm "hw:0,0"
period_time 0
period_size 2048
buffer_size 16384
format S16_LE
rate 48000
}
}
pcm.!dsnoop {
type dsnoop
ipc_key 5778293
ipc_key_add_uid yes
slave {
pcm "hw:0 ......

linux常用命令

cd                                         看盘符进入一个目录
ls       ......

完全用Linux工作 作者:王垠 (转贴 自勉)

我已经半年没有使用Windows的方式工作了。Linux高效的完成了我所有的工作。
GNU/Linux不是每个人都想用的。如果你只需要处理一般的事务,打游戏,那么你不需要了解下面这些了。
我不是一个狂热的自由软件份子,虽然我很喜欢自由软件。这篇文章也不是用来推行自由软件运动的,虽然我觉得自由软件运动是非常好的。
这篇 ......

如何在Linux使用Eclipse + CDT开发C/C++程序?

A. 为什么要在Linux使用Eclipse开发C/C++程序?
Linux是一个以C/C++开发为主的平台,无论是Kernel或是Application,主要都使用C/C++开发。传统在Linux下开发程序,是在文字模式下,利用vi等文字编辑器撰写C/C++程序存盘后,在Command line下使用gcc编译,若要debug,则使用gdb。
这种开发方式生产力并不高,若只是开发学 ......

linux中的块设备和字符设备

系统中能够随机(不需要按顺序)访问固定大小数据片(chunks
)的设备被称作块设备,这些数据片就称作块。最常见的
块设备
是硬盘,除此以外,还有软盘驱动器、CD-ROM
驱动器和闪存等等许多
其他
块设备。注意,它们都是以安装文件系统的方式使用的——这也是块设备一般的访问方式

另一种基本的设备类 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号