× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Hans Boldt
Sent: Friday, October 03, 2003 8:21 AM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: calling c++ class member function from rpg


Steve Richter wrote:

> the great one would never talk like that!
> ...

>Well, duh!  Of course it's a parody. But as with some, it had a ring
>of truth to it.

Hans, do you also "duh!" your peers or managers who dont appear to be aware
that IBM, all the serieses, need a comprehensive integrated language
environment that allows java, rpg and c++ to be used interchangeably? Not
just on the iSeries, but on the mainframe and unix also.  Similar to the
role .NET plays in windows.

>C++ is not a terribly easy language to learn or use.

Depends on the number of features you use. The programmer can start using it
as "C" and add features one at a time as the need arises.  But how is Java
an improvement?

>And although it does have a place in the realm of systems
>programming, why anyone would willingly choose it to do any
>applications programming is totally beyond me.

Ok.  That is why the smart people who make the decisions at microsoft
created visual basic and now C# and .NET managed code.  At the same time,
the smart language people at IBM have come up with what?

What follows is an example of how a feature of C++, the class destructor,
makes it possible to write very reliable ( at run time ) code. Its a feature
that, if ILE supported C++ mixed with RPG, would allow more robust
applications on the as400. I welcome anyone to prove me wrong.

I have been writing some code in windows recently that is intended to share
resources ( files, memory mapped files ) between processes ( windows ). I
have to make sure that a block of code that opens a file, closes the file
when done.  That a mutex that is acquired to block access to a shared memory
block is released when no longer needed.

To do this I had a lot of code that read like so:
  BeginExclusiveUse( ) ;
  ....
  EndExclusiveUse( ) ;

  OpenFile( xxx ) ;
  ...
  CloseFile( xxx ) ;

Which looks like it should work fine, and in the faxing system I have
deployed at a client site, where there is an RPG half running on the iSeries
and a WinFax modem/Brooktrout faxboard half running on windows, it has run
ok. But, for some known and other unknown reasons, I have been having
intermittent lockup problems on the pc side.

The problem is that sometimes the code between the BeginExclusiveUse and
EndExclusiveUse does not behave as it is expected to. And although my use of
resources is contained in c++ classes which have destructors that auto
release its resources, there are times when exceptions are thrown and caught
and the resources stay in use.

So, back to the code.  This code has lockup problems:
  BeginExclusiveUse( ) ;
  ...   // code here could bomb,
  ...   // causing EndExclusiveUse to not run.
  EndExclusiveUse( ) ;

One answer is to use try and catch
  BeginExclusiveUse( ) ;
    try
     { ... }
    catch( )
     { ... }
   EndExclusiveUse( ) ;

but that is more code and requires that my code decide what to do with the
exception. My solution is the following:

// block of resource locking code follows
  {
  ScopeExclusiveUse  seu( RefToMutex ) ;
  ...  // this code could fail.
  }

The ScopeExclusiveUse class is given a reference to a mutex that it acquires
in its constructor.  The destructor of that class then releases the mutex.
So when the code within the braces completes ( the Scope part in the name of
the class ), or it throws an exception, the destructor of the
ScopeExclusiveUse class is guaranteed to run, and release the resource (
mutex ) as it should.

So one line of C++ code:
  ScopeExclusiveUse  seu( RefToMutex ) ;

effectively replaces the BeginExclusiveUse, EndExclusiveUse, try and catch
statements.  And it does it in a more robust, failure resistant way.

I know enough Java and .NET managed code to know that the class destructor
does not work as it does in C++.  There must be a comparable way to do what
I described above in Java. I do know that RPG does not allow it.

My point is that if the IBM ILE allowed modules written in different
languages to be seamlessly mixed into an application, like MS does with
.NET, then the positive features of each language could be used to their
potential, resulting in as400 applications that run better.

-Steve



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.