This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Unexpected value-at for NULL'd pointer with pthreads
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Kyle Harper <kylejharper at gmail dot com>
- Cc: Andrew Haley <aph at redhat dot com>, Jeffrey Walton <noloader at gmail dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 24 Aug 2015 16:17:09 +0100
- Subject: Re: Unexpected value-at for NULL'd pointer with pthreads
- Authentication-results: sourceware.org; auth=none
- References: <CAPcbWWxx3g9Uk9sn5jgG1GgmxSk1fjy5ybHKuRMzdKN3LJqt2Q at mail dot gmail dot com> <CAH8yC8nSNMGkbLWWcToBX6ZP5ygFFVqjKOmjq_pnvvFmfnxqSA at mail dot gmail dot com> <CAH6eHdSw84L3t9AqUjwGkvEU=4knZJvAod+d72OgusP0F5q0pA at mail dot gmail dot com> <CAPcbWWx-CQpJQvKHdHkObJ4wRv=9idRi1PaJuJ0nScMM7o6E_g at mail dot gmail dot com> <55DAD5B7 dot 90604 at redhat dot com> <CAPcbWWw8jv6kayXL-hZKOVhbMCQGoNNbT3e5j0hvYbPfPqfFBA at mail dot gmail dot com>
On 24 August 2015 at 15:29, Kyle Harper wrote:
>
> void starting_routine(List *list) {
> // Starting point a thread will use.
> Buffer *local_buf_ptr;
> printf("%d : Thread starting up. local_buf_ptr is currently %d, ",
> pthread_self(), local_buf_ptr);
> local_buf_ptr = list->pool[0];
> printf("and is now %d\n", local_buf_ptr);
> break_crap(list, &local_buf_ptr);
Here you pass the address of a local variable.
> pthread_exit(0);
> }
>
>
> void break_crap(List *list, Buffer **buf) {
> // Emulate the buffer removal.
> pthread_mutex_lock(&list->lock);
> printf("%d : checking to see if *buf is null\n", pthread_self());
> if (*buf == NULL) {
Here you check if that local variable is null.
> printf("%d : *buf is null so I'm leaving.\n", pthread_self());
> pthread_mutex_unlock(&list->lock);
> return;
> }
> printf("%d : *buf is not null and has ID=%d and lock_id=%d,
> free()ing and NULL-ing\n", pthread_self(), (*buf)->id,
> (*buf)->lock_id);
> free(*buf);
> *buf = NULL;
You are nulling the local variable, not the array element it points to.