From 11:00 PM CST Friday, Feb 14th - 6:30 PM CST Saturday, Feb 15th, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Different Semaphore references for the same semaphore?

Solved!
Go to solution

Hi,

 

I'm wondering why the VI below outputs different semaphore references. So far I assumed that they will be the same.

 

Thanks!

 

Semaphore references.png

 

1984_0-1678957613315.png

 

0 Kudos
Message 1 of 11
(1,447 Views)

Hi 1984,

 


@1984 wrote:

So far I assumed that they will be the same.


Why did you?

You create a bunch of semaphores: each will be a new one with its own reference. But they may point to the same (LabVIEW internal) control structure…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(1,441 Views)

You get different references to the same object.

 

Internally, semaphores are just queues.

 

wiebeCARYA_0-1678958109288.png

 

This will also return false.

 

Different reference to the same object.

 

However, if you somehow get two references to a GObject (controls, nodes, wires, etc.) a compare of a different reference to the same object will return true...

 

So it doesn't seem wrong, but it is a bit inconsistent.

0 Kudos
Message 3 of 11
(1,433 Views)

@GerdW wrote:

Hi 1984,

 


@1984 wrote:

So far I assumed that they will be the same.


Why did you?

You create a bunch of semaphores: each will be a new one with its own reference. But they may point to the same (LabVIEW internal) control structure…


But they are not new semaphores. The created new output is false.

 

So, new references to the same object.

 

Comparing other references does return true if the reference is different, but pointing to the same object.

0 Kudos
Message 4 of 11
(1,431 Views)

Because I'm certainly not as clever as some other people and I often make false assumptions.

 

I thought that with whatever internal mechanism once a semaphore reference is created then if we'd like to create it again it will return the same reference. I'm clearly wrong as the VI above demonstrates, I was just surprized and wondering about the reason.

 

What do you mean on "but they may point to the same (LabVIEW internal) control structure". Is it possible that they are not?

 

Thx.

0 Kudos
Message 5 of 11
(1,424 Views)
Solution
Accepted by 1984

The good old problem of all higher level object oriented languages like Java and C#. Should an object reference comparison return true or false if the references are different but pointing to the same object. The default is to compare the reference itself and hence return false for the isEqual() method. If you want a different behaviour you have to overwrite the class method isEqual() and do a