It is currently Mon Jun 18, 2018 12:42 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Strange issue with Slim Reader Writer lock.
PostPosted: Mon Oct 16, 2017 9:05 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 783
Location: Bradenton, FL
I am getting strange problems with PB 5.45 on Windows 2008 Server using Microsoft's Slim Reader Writer library. So far, I have been unable to recreate the problems, but they occur about one every two weeks. The error number does not appear to be one easily searched.

Here are some examples:
Code:
Error Message:   Unknown error code
Error Code:      C0000264
Code Address:    776E8078
Sourcecode line: 1885
Sourcecode file: M:\Development\PureBasic\Services\OTS_CADData_service.pb

Error Message:   Unknown error code
Error Code:      C0000264
Code Address:    776E8078
Sourcecode line: 1900
Sourcecode file: M:\Development\PureBasic\Services\OTS_CADData_service.pb


The lines are:
Code:
1875    Repeat
1876        WaitForSingleObject_(thisEvent(eventNumber), monitorTime)
1877        If shutDownNow
1878            Break
1879        EndIf
1880
1881 ; get the data from the list we have built
1882
1883         AcquireSRWLockShared(*runNumberUpdates)
1884         runListSize = ListSize(runUpdates())
1885         ReleaseSRWLockShared(*runNumberUpdates)
1886
1887         If runListSize = 0
1888             Continue
1889         EndIf
1890
1891         ClearList(updateList())
1892
1893         While Not TryAcquireSRWLockExclusive(*runNumberUpdates)
1894             Delay(100)
1895         Wend
1896
1897         CopyList(runUpdates(), updateList())
1898         ClearList(runUpdates())
1899
1900        ReleaseSRWLockExclusive(*runNumberUpdates)


The error happens on the release, afters thousands of successful releases. Does anyone have a clue as to what the error might be?? The service is about 6000 lines long with all of the includes.

Thanks!
Rich


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange issue with Slim Reader Writer lock.
PostPosted: Tue Nov 14, 2017 12:40 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 783
Location: Bradenton, FL
May have found the issue with this, I have removed the ability to use 'AcquireSRW...' and will now only use the 'TryAcquire...' functions. I had assumed the 'AcquireSRW...' would block if unsuccessful. I am no longer sure this is the case.
Code:
; see if we are 64 bit or not

CompilerIf #PB_Processor_x64
    Import "..\Windows_libs\x64\kernel32.lib"
        InitializeSRWLock(*globalPointer)
        TryAcquireSRWLockShared(*globalPointer)
        ReleaseSRWLockShared(*globalPointer)
        TryAcquireSRWLockExclusive(*globalPointer)
        ReleaseSRWLockExclusive(*globalPointer)
    EndImport

; else we are 32 bit

CompilerElse
    Import "..\Windows_libs\x86\kernel32.lib"
        InitializeSRWLock(*globalPointer)
        TryAcquireSRWLockShared(*globalPointer)
        ReleaseSRWLockShared(*globalPointer)
        TryAcquireSRWLockExclusive(*globalPointer)
        ReleaseSRWLockExclusive(*globalPointer)
    EndImport
CompilerEndIf

Code:
While Not TryAcquireSRWLockShared(*globalPointer)
    Delay(20)
Wend
...
ReleaseSRWLockShared(*globalPointer)

While Not TryAcquireSRWLockExclusive(*globalPointer)
    Delay(50)
Wend
...
ReleaseSRWLockExclusive(*globalPointer)


Top
 Profile  
Reply with quote  
 Post subject: Re: Strange issue with Slim Reader Writer lock.
PostPosted: Tue Jan 09, 2018 7:50 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:50 am
Posts: 783
Location: Bradenton, FL
I think I have figured this out. The error is STATUS_RESOURCE_NOT_OWNED.

It looks like the issue is that you cannot move immediately from a shared lock to an exclusive lock? This doesn't make a lot of sense to me, but when I changed my code to using exclusive locks only, the problem seems to have disappeared.

Here are some helpful links:
http://alax.info/blog/1163
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/bug-check-0xe3--resource-not-owned
https://gist.github.com/mbrownnycnyc/24cb49aa2cba35be4764b1fa37bf9063

Here is my old code, that threw the exception. You'll see I do the shared lock first, then the exclusive lock:
Code:
; get the data from the list we have built

Repeat
    While Not TryAcquireSRWLockShared(*runNumberUpdates)
        Delay(20)
    Wend

    runListSize = ListSize(runUpdates())

    ReleaseSRWLockShared(*runNumberUpdates)

    If runListSize = 0
        Continue
    EndIf

    While Not TryAcquireSRWLockExclusive(*runNumberUpdates)
        Delay(20)
    Wend

    CopyList(runUpdates(), updateList())
    ClearList(runUpdates())

    ReleaseSRWLockExclusive(*runNumberUpdates)

    ... do work here
Forever

Here is the new code that has not thrown the C0000264, STATUS_RESOURCE_NOT_OWNED exception.
Code:
; get the data from the list we have built

Repeat
    While Not TryAcquireSRWLockExclusive(*runNumberUpdates)
        Delay(20)
    Wend

    runListSize = ListSize(runUpdates())

    If runListSize > 0
        CopyList(runUpdates(), updateList())
        ClearList(runUpdates())
    EndIf

    ReleaseSRWLockExclusive(*runNumberUpdates)

    If runListSize = 0
        Continue
    EndIf

    ... do work here
Forever

Note that code that executes shared locks on their own, seem to work fine.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye