thread argument problem

I

is_vlb50

I have problem with pass structure to thread function in SOLARIS.When I
pass it to created thread it always has empty values.

my structure defined as:
typedef struct momMSG{
struct mbhdr hd;
struct SCRIPTMSG MOMBuf;
}MY_SCRIPTMSG;

In my main function:

MY_SCRIPTMSG rcvVLMOMbuf;
--- fill rcvVLMOMbuf with values
if((rv = thr_create(NULL,0,ServerThread,(void *)
&rcvVLMOMbuf,THR_DETACHED, &tid)) == 0)

And in thread function:
void* ServerThread(void *arg)
{
MY_SCRIPTMSG* preceivedMSG = (MY_SCRIPTMSG*) arg;
}
The pointer preceivedMSG point on empty values.
What is the reason thanks
 
M

Maxim Yegorushkin

I have problem with pass structure to thread function in SOLARIS.When I
pass it to created thread it always has empty values.

my structure defined as:
typedef struct momMSG{
struct mbhdr hd;
struct SCRIPTMSG MOMBuf;
}MY_SCRIPTMSG;

In my main function:

MY_SCRIPTMSG rcvVLMOMbuf;
--- fill rcvVLMOMbuf with values
if((rv = thr_create(NULL,0,ServerThread,(void *)
&rcvVLMOMbuf,THR_DETACHED, &tid)) == 0)

And in thread function:
void* ServerThread(void *arg)
{
MY_SCRIPTMSG* preceivedMSG = (MY_SCRIPTMSG*) arg;
}
The pointer preceivedMSG point on empty values.
What is the reason thanks

A likely reason may be that you pass a pointer to a structure object on
the stack. By the time your new thread starts executing the object may
well be gone and you are left with a stale pointer. To fix allocate the
structure object on the heap using malloc() and free() it in the new
thread.
 
I

is_vlb50

You mean that I need before thr_create clone my structure MY_SCRIPTMSG
to another,allocated by malloc() ?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,483
Latest member
TedDvb6626

Latest Threads

Top