Home > pthread cleanup > pthread cleanup push compile error

Pthread Cleanup Push Compile 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 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 a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up pthread_cleanup_push causes Syntax error up vote 0 down vote favorite I try to add a section to my code which is able to unlock the mutex in a case of cancellation. This may happen and would cause a deadlock. Therefore I tried to add pthread_cleanup_push(cleanup_unlock_mutex, &mutex_ftdi); but this line cause a syntax error from the line where I add it till the end of the code file. If I comment the code line the program will compile without any error. What I'm doing wrong? void cleanup_unlock_mutex(void *p){ pthread_mutex_unlock(p); } ....... }else{ for(unsigned count=0; count <= number_of_requests; count++){ pthread_cleanup_push(cleanup_unlock_mutex, &mutex_ftdi); pthread_mutex_lock(&mutex_ftdi); process_requests(count, numberofthread); pthread_mutex_unlock(&mutex_ftdi); } } // compiler error: error: expected ‘while’ before ‘}’ token .......... All other functions in the file get the warning: ISO C forbids nested functions [-pedantic]. c pthreads mutex share|improve this question asked Jul 1 '14 at 6:39 Irgendw Pointer 6571233 2 } missed. can you indent code first? strange!!!! else without if? where is while loop? post whole code. –Jayesh Jul 1 '14 at 6:40 1 but I do not want to post the if section of the code. if you not want then anyone not want give you answer. –Jayesh Jul 1 '14 at 6:44 1 @IrgendwPointer : I believe you that only the pthread line of code is causing problem that's why you don't want to show

Invalid Undecided petter wahlman Edit You need to log in to change this bug's status. Affecting: eglibc (Ubuntu) Filed here by: petter wahlman When: 2010-05-04 Assigned: 2010-08-23 Completed: 2010-08-23 Target Distribution Baltix BOSS Juju Charms Collection Elbuntu Guadalinex Guadalinex Edu Kiwi Linux nUbuntu PLD Linux Tilix tuXlab Ubuntu Ubuntu Linaro Evaluation Build Ubuntu RTM Package (Find…) Project (Find…) Status Importance Invalid Undecided Assigned to Me petter wahlman (petter-wahlman) Comment on this change (optional) Email me about changes to http://stackoverflow.com/questions/24503877/pthread-cleanup-push-causes-syntax-error this bug report Also affects project (?) Also affects distribution/package Nominate for series Bug Description Code to trigger the problem: ================================================================ #include #include static void thread_destructor(void *arg) {     printf("die!\n"); } int main(int argc, const char *argv[]) {     pthread_cleanup_push(thread_destructor, NULL);     return 0; } Compiling results in the following errors: ================================================================ /tmp/ cc foo.c -Wall https://bugs.launchpad.net/bugs/575008 foo.c: In function ‘main’: foo.c:14: error: expected ‘while’ at end of input foo.c:14: error: expected declaration or statement at end of input foo.c:14: error: expected declaration or statement at end of input The problem is obvious if you look at the code generated by the preprocessor: ('do { } while(0)' is not terminated with '} while(0)', but 'do {' ) ================================================================ ... int main(int argc, char **argv) {     do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (((void *)0)); void *__cancel_arg = (((void *)0)); int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect (not_first_call, 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;     return 0; } The correct code should look similar to the following: ================================================================ #define pthread_cleanup_push(__thread_destructor, __arg) \ do { \     __pthread_unwind_buf_t __cancel_buf; \     void (*__cancel_routine) (void *) = (__thread_destructor); \     void *__cancel_arg = (__arg); \     int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); \     if (__builtin_expect (not_first_call, 0)) { \         __cancel_routine (__cancel_arg);

pthread https://sourceware.org/bugzilla/show_bug.cgi?id=4123 cleanup handler not called Summary: pthread cleanup handler not called Status: RESOLVED WORKSFORME Alias: None Product: glibc Classification: Unclassified Component: ports (show other bugs) Version: unspecified Importance: P2 normal Target Milestone: --- Assignee: Roland McGrath URL: Keywords: Depends on: Blocks: pthread cleanup Reported: 2007-03-02 15:18 UTC by Miroslav Kes Modified: 2010-09-03 15:16 UTC (History) CC List: 5 users (show) david.duitsman glibc-bugs kr null pth See Also: Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu, arm-xscale-be Build: i686-pc-linux-gnu Last reconfirmed: Attachments Tar file containing test program to produce the pthread cleanup push behavior with pthread_exit. (6.70 KB, application/gzip) 2007-09-08 17:37 UTC, K.R. Foley Details View All Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Miroslav Kes 2007-03-02 15:18:26 UTC I use native or crosscompiler for arm-xscale-be gcc 4.1.1 and glibc 2.5. gcc configuration: Using built-in specs. Target: i686-pc-linux-gnu Configured with: /var/tmp/portage/gcc-4.1.1-r3/work/gcc-4.1.1/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.1 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.1/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libunwind-exceptions --disable-multilib --disable-libmudflap --disable-libssp --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu Thread model: posix gcc version 4.1.1 (Gentoo 4.1.1-r3) or (the cross compiler) Using built-in specs. Target: armv5teb-softfloat-linux-gnueabi Configured with: ../gcc-4.1.1/configure --prefix=/tmp/clfs/cross-tools --host=i686-cross-linux-gnu --target=armv5teb-softfloat-linux-gnueabi --disable-multilib --with-sysroot=/tmp/clfs --disable-nls --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit --enable-c99 --enable

 

Related content

pthread cleanup push syntax error

Pthread Cleanup Push Syntax Error table id toc tbody tr td div id toctitle Contents div ul li a href Pthread cleanup pop a li li a href Pthread cleanup pop Example a li li a href Pthread cleanup pop a li ul td tr tbody table p PTHREAD CLEANUP PUSH NAME top pthread cleanup push pthread cleanup pop - push and pop thread can cellation relatedl clean-up handlers SYNOPSIS top include pthread cleanup push example pthread h void pthread cleanup push void routine void void arg void pthread cleanup pop int execute Compile p h id Pthread cleanup pop