New topic: 

Semaphores

<http://forums.realsoftware.com/viewtopic.php?t=30507>

       Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic         Author  
Message       BeauBurke           Post subject: SemaphoresPosted: Thu Oct 15, 
2009 6:18 pm                        
Joined: Thu Oct 15, 2009 6:11 pm
Posts: 2              From my understanding of the RB documentation, the 
following code should hang indefinitely on the second Signal call.

Code:
Dim foo as Semaphore

foo = new Semaphore()

foo.Signal()
foo.Signal()



Yet, it doesn't when run (or, at least, it doesn't compiled for debugging).  
The second Signal call doesn't block.  It returns immediately, just like the 
first Signal call preceding it.  Am I reading the documentation wrong?  Here's 
the text quoted verbatim:

Quote: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. If you call Signal recursively, you will cause the application to 
hang.

And for the record, I get what I expect if I call Signal from the main thread, 
then call S again from a different thread.  The second call in the other thread 
blocks until the main thread calls Release.   
                            Top                kendoll           Post subject: 
Re: SemaphoresPosted: Thu Oct 15, 2009 11:20 pm                               
Joined: Mon Jul 17, 2006 10:39 am
Posts: 1475              Causing the main thread to hang would cause troubles 
with UI elements, sockets, and other things serviced by the event loop, so this 
may be a design feature rather than a bug.  Clarification from RS would be 
nice, though.

Notably, TrySignal() also works as expected on the main thread; it returns true 
on the first call, and false on subsequent calls.     
_________________
Kenneth McCleary
http://www.upshiftcs.com/  
                            Top               BeauBurke           Post subject: 
Re: SemaphoresPosted: Fri Oct 16, 2009 12:16 am                        
Joined: Thu Oct 15, 2009 6:11 pm
Posts: 2              kendoll wrote:Causing the main thread to hang would cause 
troubles with UI elements, sockets, and other things serviced by the event 
loop, so this may be a design feature rather than a bug.  Clarification from RS 
would be nice, though.

Notably, TrySignal() also works as expected on the main thread; it returns true 
on the first call, and false on subsequent calls.

Also, to add further to the record, the above code *does* hang when executed in 
a new thread.  I'd guess this is probably another case where the documentation 
is lagging behind the implementation.  But like you said, official 
clarification would be nice.   
                            Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to