linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Hilst Selli <danielhilst@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: passing arguments to pthreads
Date: Fri, 14 Mar 2014 12:08:57 -0300	[thread overview]
Message-ID: <53231B89.2020104@gmail.com> (raw)

Hi, I have a question about passing multiple arguments to pthreads, the 
big deal is where the paremeters are kept.. I see two possible 
solutions.. keep it on static variables that are never deallocated.. or 
on heap.. so here is my first question

Passing local (stack) variables as arguments to thread is trouble, since 
the scope of this variables can go away before my thread returns..right? 
So forget about local variables

So here is the two options I see, static vs heap...
I'm using this model on one of my applications, is the same senario, a 
function that receives 3 ints as arguments and is called as a thread.. I 
create a little wrapper... here is the code http://pastebin.com/Air7u0YD


How gurus does this? I free the args on threadfd wrapper since, on my 
real application can't join the thread, to be honest, is and deatached 
thread.. Is there something wrong with this strategy, it seems ugly to 
me....

Cheers,


             reply	other threads:[~2014-03-14 15:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-14 15:08 Daniel Hilst Selli [this message]
2014-03-14 15:46 ` passing arguments to pthreads Celelibi
2014-03-14 17:30   ` Daniel Hilst Selli
2014-03-14 19:22     ` Celelibi
2014-03-18 22:21       ` Daniel Hilst Selli
2014-03-19  1:44         ` Celelibi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53231B89.2020104@gmail.com \
    --to=danielhilst@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).