From: "Gaël Deest" <GUtopiste@free.fr>
To: linux-c-programming@vger.kernel.org
Subject: Re: Strange segmentation fault with xlib / threads
Date: Sun, 30 Nov 2003 23:52:11 +0100 [thread overview]
Message-ID: <3FCA749B.9000206@free.fr> (raw)
> Can you shared with us what was the problem.
> Thanks,
I declared, at the beginning of the main :
int main(int argc, char *argv[]) {
pthread_t EventThread;
pthread_attr_t *EventThreadAttr;
with pthread_attr_t as a pointer to a a pthread_attr_t, which kind of
argument I had to pass later to the pthread_attr_init() function and
then to pthread_create(). Here are there prototypes :
int pthread_attr_init(pthread_attr_t *attr);
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *
(*start_routine)(void *), void * arg);
It was pretty useless to use the first one, I could have passed NULL as
argument in pthread_create, which would have created a concurrent
thread with the default parameters, what was the case because I didn't
modify my EventThreadAttr later.
Anyway, I simply forgot to initialize some memory for my
*EventThreadAttr, which of course caused a segmentation fault. One can
simply correct this with :
EventThreadAttr=(pthread_attr_t*)malloc(sizeof(pthread_attr_t));
I was not very logic with myself, because I used a pointer for an
argument (EventThreadAttr) and a solid variable for another one
(EventThread).
I think my program worked with an additional variable because by
enlarging its memory environment, it got access to the memory
pthread_attr_init() and pthread_create() tried to access. Which hid the
problem... It may also be interesting to know that using gcc
optimization simply deleted the problem, until the user closed the
window, when I got another strange message (don't remember what.)
next reply other threads:[~2003-11-30 22:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-30 22:52 Gaël Deest [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-11-30 18:35 Strange segmentation fault with xlib / threads Gaël Deest
2003-11-30 21:07 ` Moshe Ashkenazi
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=3FCA749B.9000206@free.fr \
--to=gutopiste@free.fr \
--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).