Home > pthread mutex initializer syntax > pthread_mutex_initializer syntax error

Pthread_mutex_initializer Syntax Error

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 pthread_mutex_init example more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags pthread_mutex_init attributes Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you,

Pthread_mutex_init Recursive

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_init Man

pthread_mutex_t mute; ImageMan() { dibSize=0; 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 pthread_cond_init 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 this error. share|improve this answer answered Jul 10 '15 at 6:11 raja ashok 3,726103761 Always try to give some explanation of answer. –serenesat Jul 10 '15 at 19:34 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged initialization pthreads mutex or ask your own question. asked 7 years ago viewed 8817 times active 1 year ago Blog Stack Overflow Podcast #92 - The Guerilla Guide to Interviewing Visit Chat Related 2Pthreads : Segmentation fault error3Using one pthread_mutex_t and multiples pthread_cond_t with pthread_cond_wa

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

Pthread_mutexattr_t

company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions pthread mutex init ebusy error Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million pthread_mutex example programmers, just like you, helping each other. Join them; it only takes a minute: Sign up PTHREAD_MUTEX_INITIALIZER inside C++ member function cannot compile? up vote 6 down vote favorite 1 class A { public: A(); private: http://stackoverflow.com/questions/383293/pthread-mutex-t-init-error pthread_mutex_t mu; }; A::A() { mu = PTHREAD_MUTEX_INITIALIZER; //cannot compile } Can't I initialize pthread_mutex_t inside a class member function? c++ pthreads share|improve this question asked Jul 26 '12 at 9:50 Alcott 4,7781263126 1 What you show is an assignment not an initialization. –Flexo♦ Jul 26 '12 at 9:54 @Flexo, OOPS, sorry. –Alcott Jul 26 '12 at 9:56 No need to apologise! –Flexo♦ Jul 26 '12 at 9:58 add http://stackoverflow.com/questions/11666718/pthread-mutex-initializer-inside-c-member-function-cannot-compile a comment| 3 Answers 3 active oldest votes up vote 8 down vote Instead of this: A::A() { mu = PTHREAD_MUTEX_INITIALIZER; //cannot compile } Try this: A::A() { pthread_mutex_init( &(mu), NULL); } The PTHREAD_MUTEX_INITIALIZER is a macro,a C struct initializer for something like {0,0,0,0,0{0}} and can only be used at the point of definition. share|improve this answer answered Jul 26 '12 at 10:03 askmish 4,4811136 add a comment| up vote 7 down vote Use pthread_mutex_init in this case, as the constant is for compile-time initialization. share|improve this answer edited Jul 26 '12 at 10:03 answered Jul 26 '12 at 9:53 Diego Sevilla 20.9k33661 Only for static pthread_mutex_t? –Alcott Jul 26 '12 at 9:57 Then I cannot put pthread_mutex_t data member in the initializtion list, can I? –Alcott Jul 26 '12 at 9:58 Sorry, I meant compile-time initialization, not static initialization. And yes, you cannot put it either (at least if not in C++11) in initialization lists. –Diego Sevilla Jul 26 '12 at 10:03 add a comment| up vote 2 down vote Even if we change this to use an initializer list in the constructor it still fails: #include struct foo { pthread_mutex_t test; foo() : test(PTHREAD_MUTEX_INITIALIZER) {} }; int main() { foo f; } We can see why it fails an

the interface may not be implemented on Linux. Name pthread_mutex_destroy, pthread_mutex_init - destroy and initialize a mutex Synopsis #include int pthread_mutex_destroy(pthread_mutex_t *mutex); int pthread_mutex_init(pthread_mutex_t *restrict mutex, const https://linux.die.net/man/3/pthread_mutex_init pthread_mutexattr_t *restrict attr); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; Description The pthread_mutex_destroy() function shall destroy the mutex object referenced by mutex; the mutex object becomes, in effect, uninitialized. An implementation may cause pthread_mutex_destroy() https://www.mkssoftware.com/docs/man3/pthread_mutex_init.3.asp to set the object referenced by mutex to an invalid value. A destroyed mutex object can be reinitialized using pthread_mutex_init(); the results of otherwise referencing the object after it has been pthread_mutex_initializer syntax destroyed are undefined. It shall be safe to destroy an initialized mutex that is unlocked. Attempting to destroy a locked mutex results in undefined behavior. The pthread_mutex_init() function shall initialize the mutex referenced by mutex with attributes specified by attr. If attr is NULL, the default mutex attributes are used; the effect shall be the same as passing the address of a default pthread_mutex_initializer syntax error mutex attributes object. Upon successful initialization, the state of the mutex becomes initialized and unlocked. Only mutex itself may be used for performing synchronization. The result of referring to copies of mutex in calls to pthread_mutex_lock(), pthread_mutex_trylock(), pthread_mutex_unlock(), and pthread_mutex_destroy() is undefined. Attempting to initialize an already initialized mutex results in undefined behavior. In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes that are statically allocated. The effect shall be equivalent to dynamic initialization by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed. Return Value If successful, the pthread_mutex_destroy() and pthread_mutex_init() functions shall return zero; otherwise, an error number shall be returned to indicate the error. The [EBUSY] and [EINVAL] error checks, if implemented, act as if they were performed immediately at the beginning of processing for the function and shall cause an error return prior to modifying the state of the mutex specified by mutex. Errors The pthread_mutex_destroy() function may fail if: EBUSY The implementation has detected an attempt to destroy the object referenced by mutex while

const pthread_mutexattr_t *attr); DESCRIPTION The pthread_mutex_init() function initializes the specified mutex. If attr is non-NULL, the attributes specified are used to initialize the mutex. If the attribute object is modified later, the mutex's attributes are not affected. If attr is NULL, the mutex is initialized with default attributes, as specified for pthread_mutexattr_init(). A mutex can be statically initialized by assigning PTHREAD_MUTEX_INITIALIZER in its definition, as follows: pthread_mutex_t def_mutex = PTHREAD_MUTEX_INITIALIZER; A mutex must be initialized (either by calling pthread_mutex_init(), or statically) before it may be used in any other mutex functions. PARAMETERS mutex Is the mutex to initialize. attr Specifies the attributes to use to initialize the mutex, or NULL if default attributes should be used. RETURN VALUES On success, pthread_mutex_init() returns 0. On error, one of the following values is returned: EAGAIN System resources (other than memory) are unavailable. EINVAL attr does not refer to a valid condition variable attribute object. EFAULT mutex or attr is an invalid pointer. ENOMEM Insufficient memory exists to initialize the mutex. CONFORMANCE POSIX P1003.1 (1996) MULTITHREAD SAFETY LEVEL MT-safe. PORTING ISSUES None. AVAILABILITY PTC MKS Toolkit for Professional Developers PTC MKS Toolkit for Enterprise Developers PTC MKS Toolkit for Enterprise Developers 64-Bit Edition SEE ALSO Functions: pthread_mutex_destroy(), pthread_mutexattr_init() PTC MKS Toolkit 10.0 Documentation Build 6.

 

Related content

No related pages.