linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Strange segmentation fault with xlib / threads
@ 2003-11-30 18:35 Gaël Deest
  2003-11-30 21:07 ` Moshe Ashkenazi
  0 siblings, 1 reply; 3+ messages in thread
From: Gaël Deest @ 2003-11-30 18:35 UTC (permalink / raw)
  To: linux-c-programming

No need to answer, I've found the problem ;-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange segmentation fault with xlib / threads
  2003-11-30 18:35 Gaël Deest
@ 2003-11-30 21:07 ` Moshe Ashkenazi
  0 siblings, 0 replies; 3+ messages in thread
From: Moshe Ashkenazi @ 2003-11-30 21:07 UTC (permalink / raw)
  To: Gaël Deest, linux-c-programming

Can you shared with us what was the problem.

Thanks,

----- Original Message ----- 
From: "Gaël Deest" <GUtopiste@free.fr>
To: <linux-c-programming@vger.kernel.org>
Sent: Sunday, November 30, 2003 8:35 PM
Subject: Strange segmentation fault with xlib / threads


> No need to answer, I've found the problem ;-)
>
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange segmentation fault with xlib / threads
@ 2003-11-30 22:52 Gaël Deest
  0 siblings, 0 replies; 3+ messages in thread
From: Gaël Deest @ 2003-11-30 22:52 UTC (permalink / raw)
  To: linux-c-programming

> 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.)



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-11-30 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-30 22:52 Strange segmentation fault with xlib / threads Gaël Deest
  -- strict thread matches above, loose matches on Subject: below --
2003-11-30 18:35 Gaël Deest
2003-11-30 21:07 ` Moshe Ashkenazi

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).