[Gambas-devel] Question about singleton class

John Leake jleake at ...741...
Sat Sep 13 22:42:17 CEST 2014


Hi Tobi,

Thanks again for your reply.  It looks like the Lock and Unlock
implementation is a very poor abstraction of lockf() and I would go as
far as to say that the functions are useless when trying to implement a
system wide singleton.

Why don't you just pass h by reference and hide all this low level
stuff.  What is the point of a high level language if the programmer has
to deal with details that are of no interest to the application.

Are you really suggesting that every where Lock is called the calling
program should first test h to see if it already has Lock ?

Some one looking at your source may see:-

if h==Null then
  Try h = Lock 'res'
  if Error.Text = "" then
    'We have lock.
  else
    'Not this time.
  endif
else
  'We have lock
endif

Instead of:-

Try h = Lock 'res'
if Error.text == "" then
  if Error.Text = "" then
    'We have lock.
  else
    'Not this time.
  endif
endif

The former example will definitely prevent any multi-threading from ever
getting into Gambas.  The latter will still work if some complex code
ends up calling Lock twice.

> You can call Lock as often as resources permit to gain as many valid locks,
> all to the same file or to many different files.

If two procs are granted Lock to the same resource it is a bug.

> during the process' lifetime? This isn't KISS anymore.

Sorry 'KISS' - what is this ?

> Under the premise that you use Lock and Unlock properly, this is equivalent
> to your lock stream being unequal to Null.

You are assuming that complex software written by large teams of
engineers contain exact Lock Unlock pairs (pie in the sky I think).

> Yep, Extern[0].

Thank you I will use Extern instead.

Best regards,
John




More information about the Devel mailing list