Hi all!

I'm trying to compile some code where I use a trylock, testing its return against EBUSY. The problem is that it won't compile because gcc says:

error: ‘EBUSY’ undeclared (first use in this function)

I'm using pthread.h and -lpthread when compiling. I also tried to unistall build-essential, update apt and download it again, but no luck.

Can someone help please?

Yup. Here's what i'm #including :P

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <dirent.h>
#include <signal.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>

(...)

   status = pthread_mutex_trylock(&do_rar);
   if(status != EBUSY)
   else (do smth)

I'm also having problems with pthread_mutex_cond. It gives me
warning: passing argument 1 of ‘pthread_cond_wait’ from incompatible pointer type

pthread_cond_wait(&(key.mutex),&(key.signal))

this particular EBUSY error was the subject of some bug fixes in GCC a few years ago. are you using an older version of GCC that might still have this bug? seems unlikely, but....

anyhow, not trying to blow you off, but since this is not standard C and it may be compiler related, you might get a quicker and more detailed response if you also try asking at GCC's forums.

gcc -dumpversion

gave me ---> gcc 4.3.3

I did search gcc homepage for the forum but it passed through me xD Although, I already found it :D

Going to try my luck, ty!

Sorry, I was wrong about <stdio.h>.
#include <errno.h> should get it -- somewhere down the chain of includes.


errno.h includes bits/errno.h includes linux/errno.h includes asm/errno.h includes asm-generic/errno.h includes asm-generic/errno-base.h which #defines EBUSY

Isn't that fun?

^ ah, yeah, i just found that, too. R.STILTSKIN is right, i believe.

you are missing the header file

#include <errno.h>

so... let me (re)learn the lesson: bugs are in user code, not compilers.
[/carlfacepalm]


.

Yup :D it worked! Thank you!
solved my EBUSY problem ;) Although, regarding my call to,

typedef struct {
   pthread_mutex_t mutex;
   pthread_cond_t signal;
   int value;
}door;

door key;

pthread_cond_wait(&(key.mutex),&(key.signal));

Still gives me the following warning,
error: incompatible type for argument 1 of ‘pthread_cond_wait’

What am I missing here? I just don't get is O.O

i dont believe you can make pointers to structure elements like that. you should pass a pointer to the entire structure into the function:

pthread_cond_wait(&key);

then in the function, you can modify/access the elements like this

(*key).mutex = whatever;

or using the shorthand method (IMO, the preferred method)

key->mutex = whatever;

.

This question has already been answered. Start a new discussion instead.