VisPro: Semaphores 
Author Message
 VisPro: Semaphores

Hi,

Can anyone shed some light for me on the use of semaphores (particularly with
the VisPro app). The documentation seems to take it for granted that one
understand the implementation of semaphores.

Right now, I'm requiring a MUTEX semaphore..

I have some code that runs once in a while which spawns a thread for a task
everytime it does so.

These threads effectively run forever constantly all the while periodically
checking the value of a global variable (VpAppVariable) the contents of
which, if appropriate, will instruct the thread to tidy up and exit.  Part of
this tidying up process is to reset the variable.

However, it is possible for the VpAppVariable to change in the time a thread
acts upon its contents and resets it from both the thread killing code and
other threads tidying up and resetting the variable... so I need to serialize
access to the VpAppVariable.

The documentation isn't too clear as to how it go about this..

Can anyone give a clue about this and semaphores in general...?

Many thanks,

Clive



Fri, 09 Feb 2001 03:00:00 GMT  
 VisPro: Semaphores
Clive,

I have code which does this kind of operation.  I regret though it is a
part of a rather largish application suite and I really don't want to
try and pull out just the parts needed for your purpose.  If you would
like I can send you a zipped copy, then we can arrange a phone call and
I can help you understand the parts.  

What you want is not very difficult, but there are a number of parts and
pieces, which makes it rather confusing, until you see the logic.  Then
it is very straight forward.

Doug Rickman

P.S. The VisPro code I have actually uses REXXLIB for the semaphores, as
the syntax is a bit cleaner and easier for my simple mind.  I actually
played with RXU, VisPro, and REXXIPC before settling on the REXXLIB
implementation.  Not a lot of difference between them.

Doug

Quote:

> Hi,

> Can anyone shed some light for me on the use of semaphores (particularly with
> the VisPro app). The documentation seems to take it for granted that one
> understand the implementation of semaphores.

> Right now, I'm requiring a MUTEX semaphore..

> I have some code that runs once in a while which spawns a thread for a task
> everytime it does so.

> These threads effectively run forever constantly all the while periodically
> checking the value of a global variable (VpAppVariable) the contents of
> which, if appropriate, will instruct the thread to tidy up and exit.  Part of
> this tidying up process is to reset the variable.

> However, it is possible for the VpAppVariable to change in the time a thread
> acts upon its contents and resets it from both the thread killing code and
> other threads tidying up and resetting the variable... so I need to serialize
> access to the VpAppVariable.

> The documentation isn't too clear as to how it go about this..

> Can anyone give a clue about this and semaphores in general...?

> Many thanks,

> Clive



Sat, 10 Feb 2001 03:00:00 GMT  
 VisPro: Semaphores

:>Clive,
:>
:>I have code which does this kind of operation.  I regret though it is a
:>part of a rather largish application suite and I really don't want to
:>try and pull out just the parts needed for your purpose.  If you would
:>like I can send you a zipped copy, then we can arrange a phone call and
:>I can help you understand the parts.  

Doug,

Many thanks for taking time to respond.  Since my post I have bitten the
bullet and written a 'prototype' app to explore semaphores...  

I was trying the gain an understanding by looking at the Error codes returned
from functions..

What was throwing me way way off was the 'Open' semaphore functions because
you can put a null string in for 'unnamed' semaphores... which would return a
semaphore ID.. but to what 'unnamed' semaphore (presuming that one can have
more than one unnamed semaphore)...

Anyway,  I decided to 'create' a semaphore and had threads requesting
access/ownership and releasing access/ownership and code between the
requests/releases executed as I expected and require it to do...  but I still
do not understand Opening a unnamed sem4 and getting the sem4 id...  As a
result, I am ignoring the Open sem4 functions....

Why use Named semaphores or Unnamed semaphores when access to them is always
through a semid variable obtained at creation which would describe the sem4
..?...  (thus all sem4s are effectively 'named' at least within the app; I'm
passing the semid var as an arg to threads...)

Or am I correct in thinking the use of Named semaphores is when one expects
an entirely separate program to be able to have access to the sem4 and thus
obtain  sem4 id variable...?... This would make sense if it was not for the
option of passing of a null string to signify opening an unnamed sem4....

Notwithstanding the Open thing, the bullet didn't have too much lead so
poisoning hasn't occurred (yet!)... although things appear to work, I'm a
little peturbed by ignoring the Open functions.. they must have some sort of
purpose..!..

I am Closing all semaphores at program end (which could be months after
program execution)....  is that right..?

Cheers!

Clive

:>>
:>> Hi,
:>>
:>> Can anyone shed some light for me on the use of semaphores (particularly with
:>> the VisPro app). The documentation seems to take it for granted that one
:>> understand the implementation of semaphores.



Sat, 10 Feb 2001 03:00:00 GMT  
 VisPro: Semaphores

Quote:

> Since my post I have bitten the bullet and written a 'prototype' app to explore
> semaphores...  
...
> Or am I correct in thinking the use of Named semaphores is when one expects
> an entirely separate program to be able to have access to the sem4 and thus
> obtain  sem4 id variable...?... This would make sense if it was not for the
> option of passing of a null string to signify opening an unnamed sem4....

> Notwithstanding the Open thing, the bullet didn't have too much lead so
> poisoning hasn't occurred (yet!)... although things appear to work, I'm a
> little peturbed by ignoring the Open functions.. they must have some sort of
> purpose..!..

> I am Closing all semaphores at program end (which could be months after
> program execution)....  is that right..?

I trust your teeth are also OK.  And if you are so inclined I assumed
you enjoyed the shot of whiskey that is "de rigueur" when it is
necessary to bite the bullet.

I close the semaphores simply because it is "tidy."  It also eliminates
some bothersome error messages that can confuse when running trace.

You are right about naming, at least as far as I know, which isn't
much.  It can also make the code easier to read if the name is
meaningful, a minor but possibly useful point.  

This is also why I prefer the REXXLIB implementation.  Their syntax uses
the name for all calls, rather than a handle value.  To illustrate I
append part of the documentation for two of the relevant calls.  By
dropping reference to the handles they have cut out one layer of logic
at the programmer's level, thus making it a good bit simpler to use.
For myself anything I don't have to master and remember means I have
more brain cells left to master what is really my job.  

Doug

From REXXLIB documentation:

 MUTEXSEM_CREATE(name,[options])

 Summary:    MUTEXSEM_CREATE creates a mutual exclusion semaphore.

 Arguments:  name:       The name of a mutual exclusion semaphore.
             options:    'O' if the semaphore should be created in an
                         owned state. The default is an unowned state.

 MUTEXSEM_QUERY(name)

 Summary:    MUTEXSEM_QUERY returns information about a mutual exclusion
             semaphore.

 Arguments:  name:   The name of a mutual exclusion semaphore.



Sun, 11 Feb 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. fortran semaphore to C semaphore

2. Semaphore>>wait:

3. Debug step in or over Semaphore>>critical: freezes VW.

4. Problem with Semaphore>>critical: ??

5. Accessing Semaphore's excessSignals

6. Question about Semaphore Lock with Netlib

7. Netware Semaphores

8. Semaphores in Netlib 6.5 D in protected mode.

9. Help! Semaphores in Netware 3.11

10. Clipper Based Semaphores?

11. Using notifiers, semaphores, etc...

12. semaphore Help

 

 
Powered by phpBB® Forum Software