Fix race in blas_thread_shutdown.

blas_server_avail was read without holding server_lock. If multiple threads call blas_thread_shutdown simultaneously, for example, by calling fork(), then they can attempt to shut down multiple times. This can lead to a segmentation fault.
This commit is contained in:
Peter Hawkins 2021-02-18 13:46:50 -05:00
parent cb429d6b12
commit dbbf92c1d1
1 changed files with 19 additions and 18 deletions

View File

@ -1024,10 +1024,10 @@ int BLASFUNC(blas_thread_shutdown)(void){
int i;
if (!blas_server_avail) return 0;
LOCK_COMMAND(&server_lock);
if (blas_server_avail) {
for (i = 0; i < blas_num_threads - 1; i++) {
@ -1051,11 +1051,12 @@ int BLASFUNC(blas_thread_shutdown)(void){
}
#ifdef NEED_STACKATTR
pthread_attr_destory(&attr);
pthread_attr_destroy(&attr);
#endif
blas_server_avail = 0;
}
UNLOCK_COMMAND(&server_lock);
return 0;