c - Is it right to use __sync_bool_compare_and_swap in multithreading environment? -
code below:
... __sync_add_and_fetch(&g_cur_mem, size); size_t curr = g_cur_mem; while ( true ) { size_t peak = g_peak_mem; if ( curr <= peak ) break; if ( __sync_bool_compare_and_swap(&g_peak_mem, peak, curr) ) break; } ... g_cur_mem global variable used save total memory used, g_peak_mem global variable used save peak value of g_cur_mem.
these code in alloc() function of memory allocator in multithreading environment.
my question is: right utilize __sync_bool_compare_and_swap in multithreading environment?
or
is code right logically in multithreading environment right peak value of g_cur_mem?
c multithreading
No comments:
Post a Comment