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

Notes for Advanced Linux Programming 4. Threads

4.  Threads
To use the POSIX standard thread API (pthreads), link libpthread.so
to your program.
4.1. Thread Creation
Each thread in a process is identified by a thread ID,
pthread_t.
The pthread_self function returns the thread ID of the current
thread.
This thread IDs can be compared with the pthread_equal
function.
if (!pthread_equal (pthread_self (),
other_thread))
    pthread_join
(other_thread, NULL);
each thread executes a thread function:
void * function(void *)
The pthread_create function creates a new thread.
A pointer to a pthread_t variable: store the thread ID of
the new thread.
A pointer to a thread attribute object. You can pass NULL
to use the default attributes.
A pointer to the thread function. void* (*) (void*)
A thread argument value of type void*.
Compile and link this program:
% cc -o thread-create thread-create.c
–lpthread
A thread exits in two ways.
return from the thread function. The function return value
is the thread return value.
explicitly call pthread_exit. The argument to pthread_exit
is the thread’s return value.
Create a Thread
#include <pthread.h>
#include <stdio.h>
/* Prints x’s to stderr. The parameter is
unused. Does not return. */
void* print_xs (void* unused)
{
    while (1)
        fputc (‘x’, stderr);
    return NULL;
}
/* The main program. */
int main ()
{
    pthread_t thread_id;
    /* Create a new thread. The new thread will run the print_xs function.
*/
    pthread_create (&thread_id, NULL, &print_xs, NULL);
    /* Print o’s continuously to stderr. */
    while (1)
        fputc (‘o’, stderr);
    return 0;
}
4.1.1. Passing Data to Threads
Listing 4.2 (thread-create2) Create Two
Threads
#include <pthread.h&g


相关文档:

Ubuntu(Linux)使用Eclipse搭建C/C++编译环境

这两天,给自己电脑弄了双系统,除了原来的Windows 7系统外,装上了Linux系统,使用的版本是Ubuntu
(点
击可到相应的下载页面)。开始我装的Linux版本是fedora9,对于一个根本没接触过Linux系统的人而言,使用fedora,简直让人崩溃。更
崩溃的是,我用的英文版。没的办法,又重新下载Linux,刻碟。装系统。装系统的时候 ......

linux—select详解

linux—select详解
select系统调用时用来让我们的程序监视多个文件句柄的状态变化的。程序会停在select这里等待,直到被监视的文件句柄有一个或多个发生了状态改变。
关于文件句柄,其实就是一个整数,通过socket函数的声明就明白了:
int socket(int domain, int type, int protocol);
我们最熟悉的句柄是0、1、2 ......

Linux EXT3文件系统下成功恢复误删的文件

  环境:CentOS 5.3 x86_64下,/dev/sdb1为数据分区/data0,EXT3文件系统。
  前因:误删了/data0/tcsql/cankao/phpcws-1.5.0/httpcws.cpp文件。由于忘了备份httpcws.cpp文件,重新开发工作量较大,因此只有恢复该文件一条路可走。
  debugfs命令针对EXT2分区还行,但对EXT3分区就帮不上忙了。偶然发现的一款开源软 ......

Freebsd与linux对比分析


FreeBSD是一个完整的操作系统,包含了从开发工具到各种各样的应用程序。
目前人们认为FreeBSD在稳定性和网络运作上的性能要优于Linux。
它由一个软件开发的核心团队来维护,整个原始程序代码会有组织地进行更新,所以程序代码比较有一致性。
由于人们对FreeBSD的认识比较少,使用范围也比较小,导致了它在对一些新产品 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号