Home > pthread mutex initializer compiler > pthread_mutex_initializer compiler error

Pthread_mutex_initializer Compiler Error

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and

Pthread_mutex_init Example

policies of this site About Us Learn more about Stack Overflow the pthread_mutex_t company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users

Pthread_mutex_destroy

Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes pthread_mutex_lock a minute: Sign up C pthread mutex: Expected expression before `{' up vote 2 down vote favorite I am using pthread library to create two threads. I am using two queues to communicate the data between the two threads (producer-consumer thing) and hence want to have a mutex to sync the push-pops in the queue by the threads. The problem I am facing is, I get a compile error as follows: $ gcc simple-tun.c simple-tun -lpthread simple-tun.c: In function ‘new_queue’: simple-tun.c:920:13: error: expected expression before ‘{’ token The the function where I get the error is: 908 struct queue * new_queue () { 909 910 struct queue * q; 911 q = (struct queue *) malloc (sizeof(struct queue)); 912 913 if (q == NULL) 914 return NULL; 915 916 917 q->head = NULL; 918 q->tail = NULL; 919 q->is_empty = 1; 920 q->mutex = PTHREAD_MUTEX_INITIALIZER; 921 922 return q; 923 } structure queue is: struct queue { 80 struct node * head; 81 struct node * tail; 82 int is_empty; 83 pthread_mutex_t mutex; 84 }; If I comment out the line 920, the linker starts giving 'multiple declaration errors' $ gcc simple-tun.c simple-tun -lpthread simple-tun: In function `settun': (.text+0x2b7): multiple definition of `settun' /tmp/cc5Ms4xP.o:simple-tun.c:(.text+0x1cb): first defined here simple-tun: In function `_fini': (.fini+0x0): multiple definition of `_fini' /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here simple-tun: In function `mktun': (.text+0x1e2): multiple definition of `mktun' /tmp/cc5Ms4xP.o:simple-tun.c:(.text+0xf6): first defined here simple-tun: In function `net_connect': (.text+0xe27): multiple definition of `net_connect' /tmp/cc5Ms4xP.o:s

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is http://stackoverflow.com/questions/17864095/c-pthread-mutex-expected-expression-before a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up pthread_mutex_t init error up vote 4 down vote favorite I am using xcode 2.4.1 on tiger. When i do below everything is ok. when i do pthread_mutex_t mute; ImageMan() { dibSize=0; http://stackoverflow.com/questions/383293/pthread-mutex-t-init-error mute = PTHREAD_MUTEX_INITIALIZER; } I get these two errors error: expected primary-expression before '{' token error: expected `;' before '{' token I dont know why. However if i do pthread_mutex_t mute = PTHREAD_MUTEX_INITIALIZER; it works fine. Why? -edit- I havent ran it but this seems to compile. Why? huh? pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; mute = mutex; initialization pthreads mutex share|improve this question asked Dec 20 '08 at 13:04 acidzombie24 43k137456818 add a comment| 2 Answers 2 active oldest votes up vote 15 down vote accepted PTHREAD_MUTEX_INITIALIZER is a constant initializer, valid when in initialization only. It is a macro that doesn't necessarily expand to an integral type. Your mute=mutex; is invalid- instead you should use: pthread_mutex_init(&mute, NULL); or if you're allocating mutexes dynamically: m = malloc(sizeof(pthread_mutex_t))); pthread_mutex_init(m, NULL); share|improve this answer answered Dec 20 '08 at 13:54 geocar 7,0891730 add a comment| up vote 0 down vote mute = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; This is an another solution for

Search HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Non-*NIX Forums > Programming C compiling error: expected expression before { token User http://www.linuxquestions.org/questions/programming-9/c-compiling-error-expected-expression-before-%91%7B%92-token-715616/ Name Remember Me? Password Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game. Notices Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use pthread_mutex_initializer compiler the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now If you have any problems pthread_mutex_initializer compiler error with the registration process or your account login, please contact us. If you need to reset your password, click here. Having a problem logging in? Please visit this page to clear all LQ-related cookies. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Search this Thread 03-30-2009, 07:06 PM #1 CoderMan Member Registered: Jan 2009 Location: Gemini Capsule 25164 Distribution: Gentoo Posts: 375 Blog Entries: 24 Rep: C compiling e

 

Related content

No related pages.