Home > pthread cleanup push error > pthread_cleanup_push error

Pthread_cleanup_push 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 pthread_cleanup_push example Us Learn more about Stack Overflow the company Business Learn more about hiring pthread_cleanup_pop developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the pthread_detach 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 pthread_create 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 your code, but please consider showing a compilable/runnable piece of code, in order that any person can try to find your error and gives you back an answer –chouaib Jul 1 '14 at 7:27 2 Why was this

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 http://stackoverflow.com/questions/24503877/pthread-cleanup-push-causes-syntax-error petter wahlman (petter-wahlman) Comment on this change (optional) Email me about changes to 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, https://bugs.launchpad.net/bugs/575008 const char *argv[]) {     pthread_cleanup_push(thread_destructor, NULL);     return 0; } Compiling results in the following errors: ================================================================ /tmp/ cc foo.c -Wall 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(__thre

Java, SQL, and other programming languages here. Search Forums Show Threads Show Posts Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to Page... linux operating commands and unix http://www.unix.com/programming/46339-pthread_cleanup_push-pop-cleanup-handler-problem.html operating commands pthread_cleanup_push/pop - cleanup handler problem Programming http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_cleanup_pop.html Thread Tools Search this Thread Display Modes #1 12-08-2007 sonicx Registered User Join Date: Aug 2007 Last Activity: 20 December 2007, 2:11 PM EST Posts: 9 Thanks: 0 Thanked 0 Times in 0 Posts pthread_cleanup_push/pop - cleanup handler problem Code: void cleanUp_delete(void * p) { delete p; p = NULL; cout pthread_cleanup_push error << "cleanUp_delete" << endl; } void connectionReader(void *thread,void*arg) { connection* c = (connection*) arg; pthread_cleanup_push(cleanUp_delete,(void*)c); int bytes; char *buffer = new (char [512]); pthread_cleanup_push(cleanUp_delete,(void*)buffer); cout << "listening for " << c->socket << " " << inet_ntoa(c->addr) << endl; while(true) { if ((bytes = read(c->socket,(void*)buffer,sizeof(char[512]))) == -1){ cout << "receive() error" << endl; break; } if(bytes == 0) break; c->buffer.append(buffer); cout << "received " << bytes << " bytes from " pthread_cleanup_push error << inet_ntoa(c->addr) << endl; cout << buffer << endl; bzero(buffer,sizeof(char[512])); } cout << "closing connection to " << c->socket << " " << inet_ntoa(c->addr) << endl; pthread_cleanup_pop(1); pthread_cleanup_pop(1); //c->~connection(); cout << "closed" << endl; pthread_exit(NULL); return; } consider this portion of code. if it wont cout that cleanUp_delete, but if uncomment thqat c->~connection(), it will segfault. so it seems the cleanUp_delete was called, because c is deleted, but why would my message not be printed? the destructor of c, called from the cleanUp handler should cout also, but doesnt. im not sure if those handlers are called in a strange way or not at all. help me out please. sonicx Remove advertisements Sponsored Links sonicx View Public Profile Find all posts by sonicx #2 12-08-2007 sonicx Registered User Join Date: Aug 2007 Last Activity: 20 December 2007, 2:11 PM EST Posts: 9 Thanks: 0 Thanked 0 Times in 0 Posts i forgot to mention: the handlers should be called when i pthread_cancel the thread running the above while it is waiting for a read(). Remove advertisements Sponsored Links sonicx View Public Profile Find all posts by sonicx #3 12-09-2007 porter Registered User Join Date: Jan 2007 Last Acti

establish cancellation handlers SYNOPSIS [THR] [Option Start] #include <pthread.h>

void pthread_cleanup_pop(int
void pthread_cleanup_push(void (*
routine)(void*), void *arg); [Option End] DESCRIPTION The pthread_cleanup_pop() function shall remove the routine at the top of the calling thread's cancellation cleanup stack and optionally invoke it (if execute is non-zero). The pthread_cleanup_push() function shall push the specified cancellation cleanup handler routine onto the calling thread's cancellation cleanup stack. The cancellation cleanup handler shall be popped from the cancellation cleanup stack and invoked with the argument arg when: The thread exits (that is, calls pthread_exit()). The thread acts upon a cancellation request. The thread calls pthread_cleanup_pop() with a non-zero execute argument. These functions may be implemented as macros. The application shall ensure that they appear as statements, and in pairs within the same lexical scope (that is, the pthread_cleanup_push() macro may be thought to expand to a token list whose first token is '{' with pthread_cleanup_pop() expanding to a token list whose last token is the corresponding '}' ). The effect of calling longjmp() or siglongjmp() is undefined if there have been any calls to pthread_cleanup_push() or pthread_cleanup_pop() made without the matching call since the jump buffer was filled. The effect of calling longjmp() or siglongjmp() from inside a cancellation cleanup handler is also undefined unless the jump buffer was also filled in the cancellation cleanup handler. The effect of the use of return, break, continue, and goto to prematurely leave a code block described by a pair of pthread_cleanup_push


Related content

No related pages.