EmbLogic's Blog

Passing a local variable in thread function

if we simply pass the address of local variable to a thread function then when that function ends then address of that variable lost(if variable is automatic) and we try to access that address or variable the it doesn’t give correct result .

I’ve resolved this problem by this way:
If i take a local variable pointer and malloc it and then pass it. when we malloc then it falls in heap segment and the it exist for the whole lifetime of program.

Please comment if any issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>