michile

导航

上一页 1 ··· 6 7 8 9 10 11 12 下一页

2013年2月3日

advacing lnux program --4.1.5 Thread Attributes[copy]

摘要: Thread attributes provide a mechanism for fine-tuning the behavior of individual threads. Recall that pthread_createaccepts an argument that is a pointer to a threadattribute object. If you pass a null pointer, the default thread attributes are used toconfigure the new thread. However, you may creat 阅读全文

posted @ 2013-02-03 12:56 michile 阅读(219) 评论(0) 推荐(0) 编辑

advacing lnux program --Threads Return Value[copy]

摘要: #include <pthread.h>#include <stdio.h>/* Compute successive prime numbers (very inefficiently). Return theNth prime number, where N is the value pointed to by *ARG. */void* compute_prime (void* arg){int candidate = 2;int n = *((int*) arg);while (1) {int factor;int is_prime = 1;/* Test pr 阅读全文

posted @ 2013-02-03 11:03 michile 阅读(200) 评论(0) 推荐(0) 编辑

advacing lnux program --Joining Threads[copy]

摘要: One solution is to force mainto wait until the other two threads are done.What weneed is a function similar to waitthat waits for a thread to finish instead of a process.That function is pthread_join,which takes two arguments: the thread ID of thethread to wait for, and a pointer to a void*variable 阅读全文

posted @ 2013-02-03 10:50 michile 阅读(124) 评论(0) 推荐(0) 编辑

advacing lnux program --thread[copy]

摘要: We’ve seen how a program can fork a child process.The child process is initiallyrunning its parent’s program, with its parent’s virtual memory, file descriptors, and soon copied.The child process can modify its memory, close file descriptors, and the likewithout affecting its parent, and vice versa. 阅读全文

posted @ 2013-02-03 00:00 michile 阅读(137) 评论(0) 推荐(0) 编辑

2013年2月2日

Cleaning Up Children Asynchronously

摘要: Listing 3.7 (sigchld.c) Cleaning Up Children by Handling SIGCHLD#include <signal.h>#include <string.h>#include <sys/types.h>#include <sys/wait.h>sig_atomic_t child_exit_status;void clean_up_child_process (int signal_number){/* Clean up the child process. */int status;wait (&a 阅读全文

posted @ 2013-02-02 23:55 michile 阅读(152) 评论(0) 推荐(0) 编辑

上一页 1 ··· 6 7 8 9 10 11 12 下一页