Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5142 Discussions

Thread Checker and shared locks?

ronmak
Beginner
804 Views

Is there support for shared (read) locks in the user-level synchronization API? I'm developing a Linux application where we do our own non-pThread and non-OpenMP mutexes. The four methods __itt_notify_sync_{prepare, cancel, acquired, releasing} appear to support only exclusive (write) locks. Am I missing something?

0 Kudos
4 Replies
Kevin_Magee__Intel_
804 Views

The __itt_notify_sync_* API calls are not limited to exclusive locks. You should be able to track a shared lock with something like:

AcquireSharedLock(){
	__itt_notify_sync_prepare((void *) &sharedLock);
	
	//code to acquire the lock goes here
	
	//begin critical section
	//increment counter
	//end critical section
	__itt_notify_sync_acquired((void *) &sharedLock);
}

ReleaseSharedLock(){
	//code to release the lock goes here
	
	//begin critical section
	//decrement counter
	if(counter == 0)
		__itt_notify_sync_releasing((void *) &sharedLock);
	//end critical section
}

Best,

-Kevin

0 Kudos
ronmak
Beginner
804 Views

Thanks, Kevin, for your reply.

My understanding is that multiple threads can hold a shared lock while reading from a critical section. But as soon as another thread grabs that shared lock in order to write into the critical section, all the reader threads are then blocked from reading the critical section until the writer thread is done writing and releases the lock.

I'm not sure that your solution enables that feature. Don't you need to tell Thread Checker whether you're holding a shared lock for reading or for writing?

Right now our shared locks cause Thread Checker to report false positives because it doesn't know that it's OK for multiple reader threads to enter a critical section while holding a shared lock.

-- Ron

0 Kudos
Kevin_Magee__Intel_
804 Views

As far as I am aware, it is not possible to acquire a write lock while other threads have read locks. The write thread should block and wait until there are no active read locks on the resource. (At least, this is the way that shared locks work in both the POSIX and Windows threading APIs.)

-Kevin

0 Kudos
ronmak
Beginner
804 Views
Yes, you're right. That's how our shared locks work, too. I'm investigating the reason for the false positives we're getting.

-- Ron
0 Kudos
Reply