LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 09-14-2011, 11:48 PM   #1
vamsi9042
LQ Newbie
 
Registered: Sep 2011
Location: Bangalore
Distribution: Ubuntu
Posts: 22

Rep: Reputation: Disabled
Question Linux threads are not working in ubuntu


Hi guys! This is vamsi krishna from india.

I'm using ubuntu 10.10.
I am trying to write a multithread program on ubuntu using C. My program is compiled fine. But only main thread is working but not the new thread. I suspect pthread_create might be failing, but it's fine. Could anybody please let me know the problem. It is the same case with centos also.

my program is:


/**********************************************************
** create.c program starts here **/
#include <stdio.h>
#include <pthread.h>

void *thFun(void *arg)
{
printf("creating new thread \n");
}

int main()
{
pthread_t th;
if(pthread_create(&th, NULL, thFun, NULL))
{
perror("create");
return;
}
printf("main\n");
}
/************************end*****************************/

compilation:
gcc -D_REENTRANT -g -Wall create.c -lpthread


I searched over net for the problem but, I couldn't get any solution in this regards.

Please get me a solution for this.

Thanks in advance.
 
Old 09-15-2011, 04:59 AM   #2
vadiml
Member
 
Registered: Oct 2003
Posts: 44

Rep: Reputation: 19
Your problem is that your main thread exits (and kill the program) BEFORE the othre thread has chance to run.
add a getchar() just before closing brace in main and you'll see.
 
1 members found this post helpful.
Old 09-15-2011, 05:28 AM   #3
vamsi9042
LQ Newbie
 
Registered: Sep 2011
Location: Bangalore
Distribution: Ubuntu
Posts: 22

Original Poster
Rep: Reputation: Disabled
Smile thank u

Quote:
Originally Posted by vadiml View Post
Your problem is that your main thread exits (and kill the program) BEFORE the othre thread has chance to run.
add a getchar() just before closing brace in main and you'll see.
Thak you very much
 
Old 09-15-2011, 11:33 AM   #4
vadiml
Member
 
Registered: Oct 2003
Posts: 44

Rep: Reputation: 19
Quote:
Originally Posted by vamsi9042 View Post
Thak you very much
Can you mark this thread as RESOLVED please?

Thanks
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write multiple threads working simultaneously ? indian Programming 3 09-19-2011 11:41 PM
ACPI Poweroff not working in Slackware12.2 - other threads, unresolved? Fedora does mitchellray Linux - Desktop 7 03-15-2009 07:22 AM
Can't get mp3's working on 10.3 despite reading other threads mwade SUSE / openSUSE 19 12-03-2007 12:21 PM
'Click Here to Find Similar Threads' not working? titanium_geek LQ Suggestions & Feedback 5 06-24-2005 09:01 PM
a ./configure doesnt see any working posix threads RokOne Linux - Software 0 04-06-2004 08:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration