From: David Schwartz on 12 Nov 2009 17:31 On Nov 12, 9:46 am, 001 <snthib...(a)gmail.com> wrote: > full buffer > 804755 [unknown (0x3C4)] prodcons 2620 _cygtls::handle_exceptions: > Error while > dumping state (probably corrupted stack) > Segmentation fault (core dumped) Looks like you're corrupting the stack. How is 'buffer' allocated? Are you sure you aren't accessing it out of bounds? DS
From: 001 on 12 Nov 2009 19:32 On 12 nov, 23:31, David Schwartz <dav...(a)webmaster.com> wrote: > On Nov 12, 9:46 am, 001 <snthib...(a)gmail.com> wrote: > > > full buffer > > 804755 [unknown (0x3C4)] prodcons 2620 _cygtls::handle_exceptions: > > Error while > > dumping state (probably corrupted stack) > > Segmentation fault (core dumped) > > Looks like you're corrupting the stack. How is 'buffer' allocated? Are > you sure you aren't accessing it out of bounds? > > DS Yup, you're right I was accessing that out of bounds too! I really ought to watch out for those things, sorry for bothering you for these stupid mistakes. Of course I ran into a lot of other problems again after that :P, but I'll stop now... I think I can handle them. Thanks! Sincerely, Stéphane
From: Chris M. Thomasson on 12 Nov 2009 12:16
"001" <snthibaud(a)gmail.com> wrote in message news:8d8af023-15f3-4d5e-8cf9-f0a01d3bd4f8(a)l2g2000yqd.googlegroups.com... > I tried to make a producer of 'items' but my implementation crashes > at > pthread_cond_wait ... I really tried looking at everything and put > print statements throughout my code, but there it just crashes. I did > put the wait within a mutex. This code isn't complete, but the > relevant parts are in there (I assume). Any idea what I did wrong? > This is the first time I used condition variables. Oh yeah... another > question: is it possible to wait on multiple condition variables (and > continue when one of them changes)? So that I can stop a thread > independent of whether or not it is waiting for something? [...] FWIW, you can do a very simple bounded circular buffer like: // pseudo-code typed in news reader. ___________________________________________________________________ #define DEPTH 8192 struct foo { char blah[128]; }; struct data { int in_use; struct foo foo; }; struct cbuf { struct data buffer[DEPTH]; /* = { { 0 } } */ size_t head; /* = 0 */ size_t tail; /* = 0 */ pthread_mutex_t mutex; pthread_cond_t cond; }; void cbuf_push(struct cbuf* self, struct foo const* f) { size_t i; pthread_mutex_lock(&self->mutex); i = (self->head++) % DEPTH; while (self->buffer[i].in_use) { pthread_cond_wait(&self->cond, &self->mutex); } self->buffer[i].foo = *f; self->buffer[i].in_use = 1; pthread_mutex_unlock(&self->mutex); pthread_cond_broadcast(&self->cond); } void cbuf_pop(struct cbuf* self, struct foo* f) { size_t i; pthread_mutex_lock(&self->mutex); i = (self->tail++) % DEPTH; while (! self->buffer[i].in_use) { pthread_cond_wait(&self->cond, &self->mutex); } *f = self->buffer[i].foo; self->buffer[i].in_use = 0; pthread_mutex_unlock(&self->mutex); pthread_cond_broadcast(&self->cond); } ___________________________________________________________________ There ya go. |