mirror of
https://github.com/amd/blis.git
synced 2026-04-19 23:28:52 +00:00
thread: free global communicator after parallel region completes in p…
* thread: free global communicator after parallel region completes in pthreads decorator Avoid potential data race by deferring free until all threads have joined. Previously, chief thread could free inside while non-chief threads still held pointers. Now, frees after the parallel region, following barrier and joins. Files: - frame/thread/bli_l3_sup_decor_pthreads.c - frame/thread/bli_l3_decor_pthreads.c * AMD-Internal: [CPUPL-7694]
This commit is contained in:
@@ -126,6 +126,12 @@ void* bli_l3_thread_entry( void* data_void )
|
||||
// Free the thread's local control tree.
|
||||
bli_l3_cntl_free( rntm_p, cntl_use, thread );
|
||||
|
||||
// NOTE: The barrier here is very important as it prevents memory being
|
||||
// released by the chief of some thread sub-group before its peers are done
|
||||
// using it. See PR #702 for more info [1].
|
||||
// [1] https://github.com/flame/blis/pull/702
|
||||
bli_thread_barrier( thread );
|
||||
|
||||
// Free the current thread's thrinfo_t structure.
|
||||
bli_l3_thrinfo_free( rntm_p, thread );
|
||||
|
||||
@@ -239,6 +245,14 @@ void bli_l3_thread_decorator
|
||||
// mutual exclusion.
|
||||
bli_sba_checkin_array( array );
|
||||
|
||||
// Now global communicator is not freed in bli_l3_thrinfo_free().
|
||||
// Free the global communicator after the parallel region completes.
|
||||
// This ensures that no thread can be using gl_comm when it is freed,
|
||||
// avoiding a potential data race where the chief thread would free
|
||||
// gl_comm inside bli_thrinfo_free() while non-chief threads might
|
||||
// still hold pointers to it.
|
||||
bli_thrcomm_free( rntm, gl_comm );
|
||||
|
||||
#ifdef BLIS_ENABLE_MEM_TRACING
|
||||
printf( "bli_l3_thread_decorator().pth: " );
|
||||
#endif
|
||||
|
||||
@@ -103,6 +103,12 @@ void* bli_l3_sup_thread_entry( void* data_void )
|
||||
thread
|
||||
);
|
||||
|
||||
// NOTE: The barrier here is very important as it prevents memory being
|
||||
// released by the chief of some thread sub-group before its peers are done
|
||||
// using it. See PR #702 for more info [1].
|
||||
// [1] https://github.com/flame/blis/pull/702
|
||||
bli_thread_barrier( thread );
|
||||
|
||||
// Free the current thread's thrinfo_t structure.
|
||||
bli_l3_sup_thrinfo_free( rntm_p, thread );
|
||||
|
||||
@@ -201,6 +207,14 @@ err_t bli_l3_sup_thread_decorator
|
||||
// mutual exclusion.
|
||||
bli_sba_checkin_array( array );
|
||||
|
||||
// Now global communicator is not freed in bli_l3_thrinfo_free().
|
||||
// Free the global communicator after the parallel region completes.
|
||||
// This ensures that no thread can be using gl_comm when it is freed,
|
||||
// avoiding a potential data race where the chief thread would free
|
||||
// gl_comm inside bli_thrinfo_free() while non-chief threads might
|
||||
// still hold pointers to it.
|
||||
bli_thrcomm_free( rntm, gl_comm );
|
||||
|
||||
#ifdef BLIS_ENABLE_MEM_TRACING
|
||||
printf( "bli_l3_thread_decorator().pth: " );
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user