Re: Mysterious syntax error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



pthread_cleanup_push(...) ==> pthread_cleanup_pop(...)

If you use one, you *MUST* use the other one.

At the end of your function:
   static void *alarm_thread(void *arg)

Add:
   pthread_cleanup_pop(0);

Guillaume.

Ian Pilcher wrote:

Apologies in advance if this is a *really* stupid question.  I'm trying
to compile the code below on Fedora Core 3 (gcc-3.4.2-6.fc3), and it's
telling me I've got a syntax error that I just can't see.

[pilcher@home temp]$ gcc -c aarg.c
aarg.c: In function `alarm_thread':
aarg.c:82: error: syntax error at end of input

I've stared at this long enough to know that, if there is an error in
the code, I'm not going to find it.  I'd really appreciate it if someone
with smarter eyes could take a look.

Thanks!


#include <stdlib.h> #include <signal.h> #include <errno.h>

#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>

typedef struct pt_alarm_s       pt_alarm_t;
typedef struct pt_alarmattr_s     pt_alarmattr_t;


enum pt_alarm_state { PT_ALARM_IDLE, PT_ALARM_SET, PT_ALARM_RUNNING, PT_ALARM_CANCELED, PT_ALARM_ERROR };

struct pt_alarm_s
{
    pthread_t                target_tid;
    pthread_t                alarm_tid;

    pthread_mutex_t         mutex;
    pthread_cond_t          cond;
    struct timespec            timeout;
    enum pt_alarm_state     state;
};

struct pt_alarmattr_s
{
    unsigned char   filler[1];
};


/*********************************************************************** * * alarm thread * **********************************************************************/

static void cleanup_alarm_mutex(void *arg)
{
    pt_alarm_t    *const alarm = arg;

    pthread_mutex_unlock(&alarm->mutex);
}

static void *alarm_thread(void *arg)
{
    pt_alarm_t    *const alarm = arg;

    pthread_cleanup_push(cleanup_alarm_mutex, arg);
    pthread_mutex_lock(&alarm->mutex);

    while (1)
    {
        int     pt_errno;

while (alarm->state != PT_ALARM_SET)
pthread_cond_wait(&alarm->cond, &alarm->mutex);
alarm->state = PT_ALARM_RUNNING;
pt_errno = 0;
while (alarm->state != PT_ALARM_CANCELED &&
pt_errno != ETIMEDOUT)
{
pt_errno = pthread_cond_timedwait(&alarm->cond,
&alarm->mutex, &alarm->timeout);
}
if (alarm->state != PT_ALARM_CANCELED)
pthread_kill(alarm->target_tid, SIGALRM);
}


    return NULL;    /* should never get here! */
}


--
=======================================
Guillaume Autran
IMAGO Laboratory - Department of Computing and Information Science
University of Guelph
Tel: (519)824-4120 ext:56645
E-mail: gautran@xxxxxxxxxxxxxxxxxxxxx
Web: http://draco.cis.uoguelph.ca/~gautran
=======================================




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux