Cursors and Multiple threads

Ruslan Zasukhin sunshine at public.kherson.ua
Sun Jun 27 19:14:00 CDT 2004


On 6/27/04 6:59 PM, "Srinivas Yalamarti" <syalamar at fiberlink.com> wrote:

Hi Srinivas,

> I wrote:
> 
>> In other words, can we get 'cursors' in a thread-safe fashion by locking
>> the db, and then 'use' the cursors without the
>> locking mechanism?
> 
> You wrote:
> 
>>> Again no.
> 
>>> Because very very often Valentina uses so called "indirect cursors".
> 
>>> Such cursor read values of the next record from original tables!
>>> I.e. It touch global single cache.
> 
> So, what does all this mean?
> 
> Does it mean, in a multi-threaded application, on a stand-alone machine
> (no valentina server used),
> only one thread can access a Valentina DB, one at a time?  All access to
> any Valentina Databases
> used by that application has to be synchronized by the application?

Yes.

But only operation that touch disk or cache.
Such as Next/Prev, Add, Update.

>       Thread A
>       ========
> 
>               VDK_Cursor* pCursorThreadA = NULL;
> 
>               LOCKDB(ONE_AND_ONLY_SYNC_OBJECT);
>                       pCursorThreadA  = m_pDatabase->SqlSelect(strSQLA,
> kServer, kReadOnly);
> 
>                       pCursorThreadA ->GetRecordCount();
> 
>                       // And also some code that uses pCursorThreadA
> 
>                       ForgetObject(pCursorThreadA );
>               UNLOCKDB(ONE_AND_ONLY_SYNC_OBJECT);
> 
>       Thread B
>       =========
>               VDK_Cursor* pCursorThreadB = NULL;
> 
>               LOCKDB(ONE_AND_ONLY_SYNC_OBJECT);
>                       pCursorThreadB  = m_pDatabase->SqlSelect(strSQLB,
> kServer, kReadOnly);
> 
>                       pCursorThreadB ->GetRecordCount();
> 
>                       // And also some code that uses pCursorThreadB
> 
>                       ForgetObject(pCursorThreadB );
>               UNLOCKDB(ONE_AND_ONLY_SYNC_OBJECT);


No, no. no.

I will try in pseudo-code
        
    
    lock
    {   
       cursor = SqlSelect() // create cursor
    }
    unlock

    lock
    {   
       cursor.firstecord() or next, prev, ...
    }
    unlock
    

    now you can read values from fields without lock.
    or assign new values

    NO LOCK:

        cursor.filedcount

        fld = cursor.field( "aaa" )

        fld->SetString( "ffsdfgdfsg" )


    again lock
    {
        cursor.AddRecord()
    }



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