LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2005, 11:27 PM   #1
iclinux
Member
 
Registered: Dec 2004
Posts: 69

Rep: Reputation: 15
can thread return a local variable?


thread_fuc returns a local variable, it's right? thanks.
//////////////////////////////////////////////////////////////////////////////////////////
#include <pthread.h>
#include <stdio.h>

void *thread_fuc(void *arg)
{
int rtn = *((int*)arg);
rtn *= rtn;
return (void *)rtn; // return a local variable, is it right?
}

int main()
{
int num = 2;
int result = 0;
pthread_t thread_id = 0;

pthread_create(&thread_id, NULL, &thread_fuc, (void *)&num);

pthread_join(thread_id, (void **)&result);

printf("result is :%d\n", result);
}
 
Old 01-13-2005, 11:37 PM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
by all means can...as long as it is not a pointer to the local variable for obvious reasons
 
  


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
can a C function return value to Shell Script variable yarnar Programming 17 06-02-2010 05:54 PM
Main thread sending notification to child thread rajesh_b Programming 1 09-22-2004 09:15 AM
configure qt thread issue (just compiled qt w/ -thread option) cleff Linux - Software 8 05-07-2004 11:11 PM
How to get 'Window' variable from a 'Widget' variable bordel Programming 0 11-19-2003 03:19 AM
How to set variable permanently in rc.local(RH7.3)? beep_beep Linux - General 7 09-25-2002 12:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:56 AM.

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