Use pthread_join to wait for the async thread to exit
This commit is contained in:
		
							parent
							
								
									6954808fd9
								
							
						
					
					
						commit
						f711dcdf6d
					
				| @ -456,7 +456,7 @@ static void *send_signal_with_delay(void *_data) { | |||||||
| // thread to send the signal to the parent thread after some specified delay.
 | // thread to send the signal to the parent thread after some specified delay.
 | ||||||
| // The delay is meant to ensure some operation in the parent thread is
 | // The delay is meant to ensure some operation in the parent thread is
 | ||||||
| // completed by the time the signal is sent.
 | // completed by the time the signal is sent.
 | ||||||
| static void raise_async(int signum, const struct timespec *delay) { | static pthread_t raise_async(int signum, const struct timespec *delay) { | ||||||
|     pthread_t thread; |     pthread_t thread; | ||||||
|     int ret; |     int ret; | ||||||
|     struct send_signal_data *data = malloc(sizeof(*data)); |     struct send_signal_data *data = malloc(sizeof(*data)); | ||||||
| @ -467,7 +467,8 @@ static void raise_async(int signum, const struct timespec *delay) { | |||||||
|         printf("ERROR: pthread_create failed unexpectedly\n"); |         printf("ERROR: pthread_create failed unexpectedly\n"); | ||||||
|         abort(); |         abort(); | ||||||
|     } |     } | ||||||
|     pthread_detach(thread); | 
 | ||||||
|  |     return thread; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int test_sigtimedwait() { | int test_sigtimedwait() { | ||||||
| @ -502,7 +503,7 @@ int test_sigtimedwait() { | |||||||
|     // pending.
 |     // pending.
 | ||||||
|     delay.tv_sec = 0; |     delay.tv_sec = 0; | ||||||
|     delay.tv_nsec = 10 * 1000 * 1000; // 10ms
 |     delay.tv_nsec = 10 * 1000 * 1000; // 10ms
 | ||||||
|     raise_async(SIGIO, &delay); |     pthread_t thread = raise_async(SIGIO, &delay); | ||||||
| 
 | 
 | ||||||
|     timeout.tv_sec = 0; |     timeout.tv_sec = 0; | ||||||
|     timeout.tv_nsec = 2 * delay.tv_nsec; |     timeout.tv_nsec = 2 * delay.tv_nsec; | ||||||
| @ -515,6 +516,10 @@ int test_sigtimedwait() { | |||||||
|     if ((ret = sigprocmask(SIG_SETMASK, &old_mask, NULL)) < 0) { |     if ((ret = sigprocmask(SIG_SETMASK, &old_mask, NULL)) < 0) { | ||||||
|         THROW_ERROR("sigprocmask failed unexpectedly"); |         THROW_ERROR("sigprocmask failed unexpectedly"); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     if (pthread_join(thread, NULL) != 0) { | ||||||
|  |         THROW_ERROR("failed to join the thread"); | ||||||
|  |     } | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user