[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference vaxaxp::vmsnotes

Title:VAX and Alpha VMS
Notice:This is a new VMSnotes, please read note 2.1
Moderator:VAXAXP::BERNARDO
Created:Wed Jan 22 1997
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:703
Total number of notes:3722

338.0. "socket programming doesn't like event flag in VMS Alpha V7.1" by BACHUS::SABLON (Mich�le Sablon, TP/IM Support Belgium 856-7238) Mon Mar 17 1997 12:20

VMS Alpha V7.1
UCX V4.1 & 4.1-4

    I'm cross-posting this note in btoth UCX and VMS note file: don't know if
    it is a VMS or an UCX problem.

    The program below is a reproducer that runs properly in V6.2 (both VAX &
    Alpha). It also runs on VAX/VMS V7.1. VAX version of UCX is also V4.1-3.
    UCX on AXP VMS V7.1 is V4.1-4. UCX on AXP VMS V6.2 is unknown.

    The program just performs some event flag initialisation, call socket then
    wait for the event flag. In V7.1, it doesn't wait anymore.

    Any idea ?
    Michele.

-----

/**************************************************************************

socket_ef.c

Problem : wait ends immediately !

AXP
OpenVMS version : 7.1
original version in CXX but the test here is in DEC C

**************************************************************************/
#include <types.h>
#include <in.h>
#include <netdb.h>
#include <inet.h>
#include <ucx$inetdef.h>
//#include <iostream.h>                         ! original version in CXX
#include <stdio.h>
#include <socket.h>
#include <starlet.h>
#include <lib$routines.h>

int listener;

void main()
{
    long efNumber;
    int  i;
    unsigned long state;
    unsigned long status;

    //Clear all events in cluster
    for (i = 63;i>32;i--)
            sys$clref (i);

    //Get free eventflag
    lib$get_ef(&efNumber);

    //Display actual state of eventflags
    sys$readef(efNumber,&state);
    //cout << "State ef's " << hex << state << endl;            ! CXX
    fprintf( stdout, "State ef's %X \n", state);

    //Get socket
    listener = socket (AF_INET, SOCK_STREAM, 0);
    if (listener == -1)
        //cout<<"SocketError "<< listener << endl;              ! CXX
    fprintf( stdout, "State ef's %X \n", state);

    //Wait on "our own" eventflag
    //cout<<"Wait on eventflag "<< dec << efNumber<<endl;       ! CXX
    fprintf( stdout, "Wait on eventflag %d \n", efNumber);
    status = sys$waitfr(efNumber);
    //cout<<"End wait. Status "<<status << endl;                ! CXX
    fprintf( stdout, "End wait. Status %d \n", status);
}

/*

$ cc/prefix=all socket_ef
$ link socket_ef
$ socket_ef

$! On VAX VMS V6.2 and V7.1:
State ef's 0
State ef's 40000000
Wait on eventflag 63
 Interrupt

$ stop

$! On VMS Alpha V7.1:
State ef's 0
State ef's 80000000
Wait on eventflag 63
End wait. Status 1
$

That's it !
*/

T.RTitleUserPersonal
Name
DateLines
338.1Code Error, Possible UCX Error...XDELTA::HOFFMANSteve, OpenVMS EngineeringMon Mar 17 1997 13:399
   This appears a UCX question...

   Note that a blind sys$clref(i) is entirely bogus, as it's munging
   the state of event flags potentially not "owned" by this code...

   If you're going to be using event flags and OpenVMS-isms, consider
   using the sys$qio[w] interface into BGDRIVER.

338.2AUSS::GARSONDECcharity Program OfficeMon Mar 17 1997 21:044
    re .0
    
    It looks like a bug in socket(). You should report it formally to
    whoever owns that routine.
338.3not necessarily a bug...GIDDAY::GILLINGSa crucible of informative mistakesMon Mar 17 1997 22:3937
  re .0:

>$! On VAX VMS V6.2 and V7.1:
>State ef's 0
>State ef's 40000000
>Wait on eventflag 63
> Interrupt
>
>$ stop
>
>$! On VMS Alpha V7.1:
>State ef's 0
>State ef's 80000000
>Wait on eventflag 63
>End wait. Status 1
>$

  As you can see from the state mask, EF 63 is set, so it's not surprising
  that you're not waiting. The flag is clear on older versions.

  Your output doesn't actually match your program (which won't compile).
  Rearranging the display of the state mask shows event flag 63 being set
  by the call to socket. Note that although you have allocated the event
  flag, it's not necessarily a fault in "socket". Any algorithm which uses
  an event flag for synchronisation should (must?) be able to deal with false
  settings, so you should pair your event flag with a status block (see
  SYS$SYNCH for a description). By convention, any use of an event flag
  should leave the event flag in SET state, to protect other users against
  missed signals.

  "socket" may be being anti-social, but not necessarily incorrect (but
  that's nothing new from unix derived code on OpenVMS). LIB$GET_EF is
  no more than a "gentleman's agreement" which is not enforced. Further,
  since event flags are a very scarce resource, it's often necessary that
  they be overloaded. If correctly coded, overloadings should not matter.

						John Gillings, Sydney CSC
338.4Speculation on what changedWIBBIN::NOYCEPulling weeds, pickin&#039; stonesTue Mar 18 1997 09:2511
I experimented with this on V6.2 (Alpha).  If you vary the number of times
you call LIB$GET_EF, then the event flag # that gets set by socket() varies.
It sure looks as if socket() calls LIB$GET_EF too.

Perhaps on V7.1 socket() is built incorrectly, such that it includes its own
copy of LIB$GET_EF, rather than referring to the one in LIBRTL.EXE.  That
would make it think that EF #63 is available when it's not.  This would be
a bug in the way socket is built, in my opinion.  But you should still write
your code in such a way as to defend against an event flag getting spuriously
set...  What is it that you're waiting for in the real application?  That is,
what is the setting of that event flag supposed to represent?
338.5in VMS 7.1 socket() set ef 63 !BACHUS::SABLONMich�le Sablon, TP/IM Support Belgium 856-7238Tue Mar 18 1997 10:1555
re .1:
>>  Note that a blind sys$clref(i) is entirely bogus, as it's munging
>>  the state of event flags potentially not "owned" by this code...

    Note this is just a reproducer. The customer adds this call to be sure of 
    the environment.

>>  If you're going to be using event flags and OpenVMS-isms, consider
>>  using the sys$qio[w] interface into BGDRIVER.

    Does this means that one should NOT use socket programming while using VMS 
    feature ? This is VERY important to know: this customer is currently looking 
    at various new VMS features to be used, like (kernel) threads. I believe he 
    is looking to event flag as a potential synchronization mechanism in an 
    environment mixing threads and ASTs !

re .3:
>>  Your output doesn't actually match your program (which won't compile).

    Sorry for that, a cut and paste problem. The program is in fact as:

    ...
    //Get socket
    listener = socket (AF_INET, SOCK_STREAM, 0);
    if (listener == -1)
        //cout<<"SocketError "<< listener << endl;
        fprintf( stdout, "SocketError %d \n", listener);

    //Display actual state of eventflags
    sys$readef(efNumber,&state);
    //cout << "State ef's " << hex << state << endl;
    fprintf( stdout, "State ef's %X \n", state);
    ...

    I went further with this example and it appears to me that socket() 
    effectively set the event flag #63. 

>>  Any algorithm which uses an event flag for synchronisation should (must?) 
    be able to deal with false settings, so you should pair your event flag 
    with a status block (see SYS$SYNCH for a description). ...

     I'll feedback this.

re .4:
>>  If you vary the number of times you call LIB$GET_EF, then the event flag 
>>  # that gets set by socket() varies. It sure looks as if socket() calls
>>  LIB$GET_EF too.

    It is what it is expected to do. I continued on VMS 7.1 and got always the 
    same EF 63 set by socket().

In any case, thanks a lot to all of you. I'm escalating the problem to UCX.
Best,
Mich�le.
338.6New AST Chapter In ProgressXDELTA::HOFFMANSteve, OpenVMS EngineeringTue Mar 18 1997 10:5858
:>>  Note that a blind sys$clref(i) is entirely bogus, as it's munging
:>>  the state of event flags potentially not "owned" by this code...
:
:    Note this is just a reproducer. The customer adds this call to be sure of 
:    the environment.

   It's still bogus -- you're "spuriously" resetting the event flags,
   which can cause problems for other (poorly-written) code.  And the
   flags can still switch states depending on other activity.  (In other
   words, keep the manipulations to these event flags you have allocated.)

:>>  If you're going to be using event flags and OpenVMS-isms, consider
:>>  using the sys$qio[w] interface into BGDRIVER.
:
:    Does this means that one should NOT use socket programming while using VMS 
:    feature ?

   No, it means that if you are going to "lace" the code with OpenVMS
   features (and are thus not highly concerned with portability), you
   may find the $qio[w] interface far more flexible, and more powerful
   than the traditional UNIX "socket" interface.  Probably the biggest
   benefit: the BGDRIVER interface has AST notification, and this is
   not available via the "socket" interface.

:    This is VERY important to know: this customer is currently looking 
:    at various new VMS features to be used, like (kernel) threads.

   Event flags provide a simple solution to many problems.  They tend
   to get restrictive as more threads are added, and as more complex
   applications are involved...  (I usually prefer to use ASTs, $hiber
   and $wake, and the interlocked primitives -- or use DECthreads...)
  
:    I believe he is looking to event flag as a potential synchronization
:    mechanism in an  environment mixing threads and ASTs !

   Check with the DECthreads folks and see what they recommend here,
   around mixing threads and ASTs.  (And this question has undoubtedly
   already been asked...)

:>>  If you vary the number of times you call LIB$GET_EF, then the event flag 
:>>  # that gets set by socket() varies. It sure looks as if socket() calls
:>>  LIB$GET_EF too.
:
:    It is what it is expected to do. I continued on VMS 7.1 and got always the 
:    same EF 63 set by socket().

   You are jumping to a conclusion based on limited data -- you will not
   always receive event flag 63, save for the simplest of test cases...

   --

   As was mentioned, spurious $wake and spurious event flags should be
   expected.  And one should be *very* careful around the specification
   of ASTs and IOSBs -- there's likely a replacement AST chapter going
   into the "Raven" OpenVMS release Programming Concepts manual...  (It
   is not quite ready, but I may be able to send you a review copy, when
   it becomes available.)

338.7BACHUS::SABLONMich�le Sablon, TP/IM Support Belgium 856-7238Tue Mar 18 1997 12:0215
Hi Steve,

My test data are surely limitted by I modify the program to get and set 3 event
flags then call socket(). I may run this program numbers of time, it always get
event flag 63, 62 and 61.

If I don't set the flags, just get them, the socket() set it, but only flag 63.
If I have set the flags then clear then again, socket() doesn't set it ?!

Seems me really strange !

by the way, I'll surely be interested by the update version of the Programming
Concept Manual. I just receive the V7.1 one which seems already interesting.

Best,
Mich�le.
338.8http://comet.alf.dec.com/XDELTA::HOFFMANSteve, OpenVMS EngineeringThu Mar 20 1997 14:239
  Search for "CTI_SRC961219005807" and/or for "[DEC TCP/IP] V4.1
  Incorrectly Uses EF Not Allocated By UCX" in COMET...

  There is a patch to the UCX$IPC_SHR image either in progress,
  or available.

  COMET URL: http://comet.alf.dec.com/

338.9Eco solve the problemBACHUS::SABLONMich�le Sablon, TP/IM Support Belgium 856-7238Mon Mar 24 1997 07:397
Yes Steve,

I effectively found this information meanwhile and applied the patch. It solves
the problem.

Thanks for all,
Mich�le.