Results 1 to 30 of 30

Thread: how to check if Mutex is Released

Threaded View

  1. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    376

    Re: how to check if Mutex is Released

    i think the code u provided above would not work:
    Code:
     Get
                If InSet Then
                    SyncLock Lock
                        Return _SomeString
                    End SyncLock
                Else
                    Return _SomeString
                End If
            End Get
    because after you have Returned, everything else below it does not run. So the Lock never gets released. so what we have is this:
    Code:
     Get
                If InSet Then
                    SyncLock Lock
                    End SyncLock
                    Return _SomeString
                Else
                    Return _SomeString
                End If
            End Get
    there's 2 reasons why i do not wish to use SyncLock. number one is obviously we are created an object for just Synclocking, another and more Importantly is that there is a delay in SyncLock compared to using the Do While method.

    During:
    Code:
            SyncLock Lock
                    End SyncLock
    the thread steals priority and prevents other from reading. So if i had like 10 threads trying to do a Get, i want them to be able to occur simultaneously, in any order, because it would still be ThreadSafe (unless someone decides to do a Set). But using SyncLock, the 10 threads had to do it one by one, even if its fast, its still one by one, whereas Do While allows all of them to do Straight away without waiting for any

    Code:
    Do While allowed_to_do_a_get
    Loop
    Well of course 0 loops are taking place if allowed_to_do_a_get is set to True. I think the real problem is that alot of loops will take place if someone is Setting (which will set allowed_to_do_a_get to false)

    Is there a better way to do things, a SyncLock that doesn't cause delay?




    also,
    if it sees that this SyncBlock is owned by another thread then it will suspend this thread and wait for the other thread to release the SyncBlock so that it can then take ownership.
    so how does he actually know that the SyncBlock is released, doesn't he have to check it every now and then to see if SyncBlock is released? (which means a loop)
    Last edited by pacerier; Dec 24th, 2009 at 11:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width