Example 63 Detecting multi-threaded programming issues
#include<PTHREAD.H> #include <STDIO.H> int a; pthread_mutex_t Mutex;
void perform_operation(pthread_mutex_t* mutex1, int increment, int* global)
{
if (increment > 10)
{
int status = pthread_mutex_lock(mutex1);
}
*global = *global + increment;
int status = pthread_mutex_unlock(&Mutex);
}
int main(void)
{
int i; scanf("%d", &i);
perform_operation(&Mutex, i, &a); printf("%d is value\n", a);
}
Running cadvise generates the following error:
"1.c", line 12: warning
With the +wlock option, warnings are generated for potential errors in using lock/unlock calls from pthread library. This is based on
This may lead to a significant increase in the compile time compared to a build without the +wlock option.
The +wlock option requires cross module analysis. Hence, you need to specify the location of the PDB using the
8.7 Detecting potential performance improvement opportunities
The +wperfadvice[=1234] option generates Performance Advisory diagnostics. The performance advisory diagnostics are classified within specific levels. You can specify the level of performance advisory diagnostics to be displayed. The level '1', emits the most important diagnostics and level '4' emits all diagnostics. The default level is '2'.