当前位置: 技术问答>linux和unix
linux多进程多线程问题
来源: 互联网 发布时间:2016-07-23
本文导语: 本帖最后由 hail08 于 2009-12-16 08:59:18 编辑 这里为什么子进程创建的线程ID相同的? #include #include #include #include static int temp; void thread1 (void *arg) { pthread_t thid = pthread_self (); printf ("thread1 Current thread's...
#include
#include
#include
#include
static int temp;
void
thread1 (void *arg)
{
pthread_t thid = pthread_self ();
printf ("thread1 Current thread's ID is %d n", (int) thid);
printf ("thread1 endsn");
}
void
thread3 (void *arg)
{
pthread_t thid = pthread_self ();
printf ("thread3 Current thread's ID is %d n", (int) thid);
printf ("thread3 endsn");
}
void
thread2 (void *arg)
{
pthread_t thid = pthread_self ();
printf ("thread2 Current thread's ID is %dn", (int) thid);
printf ("thread2 endsn");
}
void createthread()
{
pthread_t thid1,thid2;
if(pthread_create(&thid1, NULL, thread1, NULL) != 0) {
printf("thread creation failedn");
exit(1);
}
if(pthread_create(&thid2, NULL, thread2, NULL) != 0) {
printf("thread creation failedn");
exit(1);
}
}
int
main()
{
pid_t status;
int i,j;
printf ("Process Creation Study ppid= %d,pid=%dn",getppid(),getpid());
for (i = 0; i