Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-14-2005, 12:27 AM   #1
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-14-2005, 12:37 AM   #2
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 06:54 PM
Main thread sending notification to child thread rajesh_b Programming 1 09-22-2004 10:15 AM
configure qt thread issue (just compiled qt w/ -thread option) cleff Linux - Software 8 05-08-2004 12:11 AM
How to get 'Window' variable from a 'Widget' variable bordel Programming 0 11-19-2003 04:19 AM
How to set variable permanently in rc.local(RH7.3)? beep_beep Linux - General 7 09-25-2002 01:35 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 PM.

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