How long do we have to (mutex) lock Valentina operations for Mac OS X thread-safety?

Matthew Jew mjew at icnc.com
Tue Aug 5 19:33:07 CDT 2003


I am aware that in the current version of Valentina, one should get a 
mutex lock
for the entire Valentina engine for thread safety. This is OK, and 
should work for me.
(I am speaking of working in the Mac OS X environment with preemptive 
threads,
  not cooperative threads that explicitly yield to each other.)

My question is this: What should one consider the "duration" of the 
Valentina operation
that one has to lock for? Is it just

1. During actual calls into the Valentina engine, or
2. Anytime your code is "holding" data structures returned by 
Valentina, or
3. Sometimes #1, sometimes #2 depending on what the data structure is.

For example (from Example1(ANSI))

void MyDataBase::SortRecords( void )
{
	LockValentinaEngine();	// Get mutex
	FBL_BitSet* pAllSet = mBaseObject1.SelectAllRecords();

	// We want to sort selection on 2 fields: { Field1, Field2 }
	// Create sort order array:
	VDK_SortOrder Order;

	Order.AddItem( new VDK_SortItem(&mBaseObject1.mfField1) );
	Order.AddItem( new VDK_SortItem(&mBaseObject1.mfField2) );

	// Now we sort selection on fields,
	// pAllSet will be destroyed by Sort() !!!
	// As sorted selection we get FBL_ArraySet but not FBL_BitSet.
	FBL_ArraySet* pSortedSet = mBaseObject1.Sort( pAllSet, &Order );
	
	// Is is safe to unlock here?
	UnlockValentinaEngine();	// Release mutex

	// Do something with the returned FBL_ArraySet*
	int	recordsFound = pSortedSet->GetCount();
	for ( int i = 1; i <= recordsFound; i++ )
	{
		// Do something here with records
	}

	// Watch for memory allocation
	FBL_Deleter<FBL_ArraySet> Killer( pSortedSet );

	// Or do we have to wait until here to unlock?
	//UnlockValentinaEngine();	// Release mutex

	// now we can iterate sorted selection by iterator.
}

Without knowing more about how the memory for the FBL_ArraySet is 
allocated
and who controls it, I could not guess the answer.

Does anyone know?

- Matthew



More information about the Valentina mailing list