Sponsored Content
Full Discussion: Infinite thread
Top Forums Programming Infinite thread Post 302482641 by Praveen_218 on Wednesday 22nd of December 2010 06:50:43 AM
Old 12-22-2010
Under normal & trivial circumstances, in your case, your pthread is never going to die, because the execution in context to this thread doesn't reaches past the ending curly braces }.

Also main is a non-terminating again.

Here are the general cases, a pthread dies:

Code:
1) When there is an explicit call to pthread_exit()

2) When the execution reaches the end curly braces; i.e. the handler function has been executed and/or returns.

3) When the main() terminates; results in the clean up of all the program stack and memory recovery by the OS; lets get the pthread stack cleaned up.

Now coming to few more general cases pertaining to your present code:

Code:
1) You haven't handled any signal/interrupts; so don't expect it to run for years. In other words, its a no robust code. Hence, the moment main()
 is gone, your thread would go.

2) main() is in the busy wait; most of the OS kernel scheduler would detect this easily and (untill explictly elevated in terms of priority) would run off with a low priority in scheduling 
--happens in Linux (trick to overcome in busy wait is to put a few miliseconds of sleep  --but can't generalize this for other OS). 
Instead why don't you just blocked wait in pthread_join() and do that function call in another seperate pthread?


Last edited by Praveen_218; 12-22-2010 at 10:10 AM..
 

5 More Discussions You Might Find Interesting

1. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies

2. Programming

high priority thread contains an infinite loop

Hi, Assume there are 3 threads N1, N2, N3. in N1 { .... while(1) { } } when the thread N1 got the time slice, it started executing the infinite loop.. Note:there is no condition inside the while(1) to end the infinite loop I heard that some RTOS will solve this problem... (0 Replies)
Discussion started by: rvan
0 Replies

3. Shell Programming and Scripting

Infinite while loop

what is the difference between while:,while true and while false? (6 Replies)
Discussion started by: proactiveaditya
6 Replies

4. Homework & Coursework Questions

Help with infinite loop problem

1. The problem statement, all variables and given/known data: My problem is an infinite loop when i press any other key other then Y or y in the while loop. what i want it to do is return to the normal script outside of it if pressing N or n or keep asking the same question if its any other... (4 Replies)
Discussion started by: Ren_kun
4 Replies

5. Shell Programming and Scripting

How to stop infinite loop

Im unable to stop the below infinite loop (bash script). Can someone tell me why this isnt responding to signals eg: ctrl+c (SIGINT) or ctrl+z c=0 test_loop() { c=$(($c+1)) echo "count value is : $c " sleep 1 test_loop } Im using: SunOS 5.10 PS: If run this as... (13 Replies)
Discussion started by: Arun_Linux
13 Replies
iv_thread(3)						    ivykis programmer's manual						      iv_thread(3)

NAME
iv_thread_create, iv_thread_set_debug_state - ivykis thread convenience functions SYNOPSIS
#include <iv_thread.h> int iv_thread_create(char *name, void (*start_routine)(void *), void *arg); void iv_thread_set_debug_state(int state); DESCRIPTION
iv_thread_create is a wrapper around pthread_create(3) which will maintain an ivykis main loop reference in the calling thread (which must be an ivykis(3) thread, i.e. have had iv_init(3) called in it) for as long as the created thread is alive. Maintaining a reference on the calling thread's ivykis event loop makes sure that the calling thread will not return from its ivykis main loop before the created thread exits, as that could cause cleanup still happening in the created thread to be interrupted when the calling thread subsequently calls exit(3). The created thread need not be an ivykis thread. Enabling debugging by calling iv_thread_set_debug with a nonzero argument will print a debug message to standard error whenever a thread is created via iv_thread_create, whenever a thread so created terminates normally by returning from its start_routine, self-terminates by calling pthread_exit(3), or is successfully canceled by pthread_cancel(3), and whenever destruction of such a thread is signaled back to the calling thread. For inter-thread signaling, iv_thread uses iv_event(3). SEE ALSO
ivykis(3), iv_event(3), exit(3), pthread_cancel(3), pthread_create(3), pthread_exit(3) ivykis 2010-09-13 iv_thread(3)
All times are GMT -4. The time now is 07:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy