User's Manual

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 #20223-D: Trying to unlock a lock held conditionally
With the +wlock option, warnings are generated for potential errors in using lock/unlock calls
from pthread library. This is based on cross-module analysis performed by the compiler, which is
much more powerful compared to simple scanning and parsing tools. The +wlock option implicitly
enables a limited form of cross-module analysis even if -ipo or +O4 options are not specified.
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 -pdb option.
8.7 Detecting potential performance improvement opportunities
The +wperfadvice[=1|2|3|4] 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'.
54 Categories of diagnostics with examples