LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-21-2010, 06:48 AM   #1
Khaj.pandey
LQ Newbie
 
Registered: Apr 2010
Posts: 12

Rep: Reputation: 0
Pthreads problem


Hello,
I am playing around with pthreads. This program how ever blows up.



Quote:
#include <iostream>
#include <pthread.h>

using namespace std;

struct myStruct
{
int a;
string msg;
};

void * myProc(void *arg)
{
struct myStruct* str = new struct myStruct();
str->a = 10;
str->msg ="hi";
return (void*)str;
}

int main(int argc, char **argv)
{

pthread_t mythr;
int status ;
void *retVal;
struct myStruct* m_str;
status = pthread_create(&mythr,NULL,myProc,NULL);
status = pthread_join(mythr,&retVal);
cout<<"Status is"<<status<<endl;
m_str = (struct myStruct*)m_str;
cout<<"retval is "<<m_str->a<<" "<<endl;
return 0;
}

Can a structure be returned by a thread as its return value ?
 
Old 05-21-2010, 06:55 AM   #2
Khaj.pandey
LQ Newbie
 
Registered: Apr 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Sorry i guess i jumped the gun...


m_str = (struct myStruct*)m_str;



m_str = (struct myStruct*)retVal;

Cheers!
 
  


Reply


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
Pthreads in c++ brevleq Programming 11 11-14-2009 04:52 AM
pthreads ftgow Linux - Software 0 07-08-2004 03:55 AM
Problem with huge number of pthreads Berng Programming 7 12-17-2003 07:33 AM
pthreads Keith Hampton Linux - Software 1 10-23-2003 01:46 PM
Problem with atoi in pthreads jones507 Programming 1 10-16-2003 02:42 PM


All times are GMT -5. The time now is 01:11 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration