473,388 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

thread argument problem

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

Feb 28 '06 #1
3 2123

is******@hotmail.com wrote:
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.

Feb 28 '06 #2
You mean that I need before thr_create clone my structure MY_SCRIPTMSG
to another,allocated by malloc() ?
Thanks

Feb 28 '06 #3
In article <11*********************@j33g2000cwa.googlegroups. com>,
is******@hotmail.com wrote:
You mean that I need before thr_create clone my structure MY_SCRIPTMSG
to another,allocated by malloc() ?
Thanks


Yes.

P.S. Please include context so your question makes sense. See

http://cfaj.freeshell.org/google/

--
Barry Margolin, ba****@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Feb 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
22
by: Morpheus | last post by:
Hi, I have been coding in Windows for many years so have a mindset to it, so forgive any stupid questions. Is it possible to create a multithread application in C++ that is portable...
4
by: eBob.com | last post by:
In my class which contains the code for my worker thread I have ... Public MustInherit Class Base_Miner #Region " Delegates for accessing main UI form " Delegate Sub DelegAddProgressBar(ByVal...
16
by: Hendrik van Rooyen | last post by:
I thought I would share this nasty little gotcha with the group. Consider the following code fragment: <start> print 'starting kbd thread' keyboard_thread = thread.start_new_thread(kbd_driver...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.