On Apr 15, 2006, at 3:52 AM, Jeffrey Mattox wrote:
1. Create a new project.
2. Add a PushButton.
3. Put this as the Action:
Dim sm as Semaphore
sm = new Semaphore
sm.Signal
sm.Signal
beep
Me.Caption = "bug"
4. Press the button.
It should block on the second sm.Signal, but it falls right through
and beeps. Is it me, or an RB bug?
I believe this is because signal works on a thread level. Once you
call signal from a thread, in this case the main thread and no other
resource has a lock on your semaphore, then the signal call simply
returns and puts a lock that belongs to your thread on the
semaphore. The second time you call signal from the same thread,
your thread already has the lock so signal does not block and you
are free to continue. I think you need to test this with at least
one other thread to see it in action. I haven't tested this myself
in a while, but I believe what I stated is correct. I'm sure someone
will chime in if I'm mistaken.
Kevin
You are describing a CriticalSection. The documentation for
Semaphore is explicit that the counter will decrement even in the
same thread. By inference, it's a CriticalSection that does not
decrement a second time in the same thread. To wit, the
documentation for Semaphore states:
The Semaphore class is different from the CriticalSection
and Mutex classes in this way: calling Signal in the same
thread will cause the counter to decrement.
The main thread (controlling the GUI) is a thread, too. So, I still
believe my code should block.
Jeff
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>