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

Ruslan Zasukhin sunshine at public.kherson.ua
Wed Aug 6 11:47:04 CDT 2003


on 8/6/03 5:33, Matthew Jew at mjew at icnc.com wrote:

> 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

yes

> 2. Anytime your code is "holding" data structures returned by
> Valentina, or

No. If you going to have multi-thread app, then Cursors can help,
Because each cursor have own buffer and own current record.

If you not use cursors, but use Sets and BaseObject API, then you can see
that each thread will jump/change the current record of BaseObject.
I.e. You need or provide own buffers for values, or protect BaseObject while
one thread work with it.

> 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.

-- 
Best regards,
Ruslan Zasukhin      [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com

To subscribe to the Valentina mail list go to:
http://lists.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------



More information about the Valentina mailing list