Locked, what does "stacked in the current process" mean?

In the documentation for Locked, https://doc.4d.com/4Dv15/4D/15.6/Locked.301-3817809.en.html, what does “stacked in the current process” mean?

Thanks,
Drew

When 4D loads a record, the record is put into the stack of the current process with the current locked status. Suppose your current process is loading record “A” that is locked by another process, the record in the stack will have the locked status of “True”. This status will not change even after the record is released by the process that was locking it. The command Locked will return False only change when the record is reloaded. Basically 4D pops the current record from the stack and push the same record with the current locked status back in.

1 Like

Hi Add,

A bug ACI0090824 (taow 129758) has been opened and is under study since… July 2014!

Here’s the demo 18R3:

READ ONLY(*)
ALL RECORDS([Table_1])
$B_Locked:=Locked([Table_1]) // false
LOCKED BY([Table_1];$process;$user;$sessionUser;$processName)

READ WRITE([Table_1])  // when reaching this line, launch a process then delete the record
LOAD RECORD([Table_1])
$B_Locked:=Locked([Table_1])  // what should be $B_Locked : true or false?
LOCKED BY([Table_1];$process;$user;$sessionUser;$processName)

The 2nd $B_Locked should be True according the documentation. In fact it returns False

I gave up but in case you have more relation than me at 4D :thinking:

Hi Bertrand,

I believe the behavior you are seeing is exactly what should happen. Here is a simple way to look at the Locked command. When a record is locked (Locked([Table_1]) return True), it simply means that your current process is not permitted to modify the record. When a record is not locked (Locked([Table_1]) return False), it means that the current process is permitted to modify the record.

So in your example, the 2nd Locked execution should return False, implying that no one else is locking this record and that the current process is permitted to modify.

Add

Also, I’m testing the code in 18.1 HF1 and the 1st Locked returns True. I haven’t tested in R3 yet.

Add,
I meant, when the record has been deleted, Locked command returns False when the doc writes True. I just want to point this. A demo is available on taow.

My test on 4Dv18R3Build251808 …Mono(not C/S) on OSX
have shown correct expected and documented behavior.
Here my code snipped to test it:

  // https://doc.4d.com/4Dv18R3/4D/18-R3/LOAD-RECORD.301-4901525.en.html
  // - If table is in read-only state, the Locked function returns TRUE, and you cannot modify the record !!!
  // - If table is in read/write state but the record was already locked, the record will be read-only, and you cannot modify the record.
  // - If table is in read/write state and the record is not locked, you can modify the record in the current process. The Locked function returns TRUE for all other users and processes.

  // READ ONLY(*)  // With optional * parameter all tables changed to read-only state for currentProcess
  // READ ONLY  // empty means, changes state of Default table to read-only for currentProcess

  // first unload record and selection (if something is just loaded before)
UNLOAD RECORD([person])
REDUCE SELECTION([person];0)

READ ONLY([person])  // changes state of this one table to read-only for currentProcess
ALL RECORDS([person])  // ALL RECORDS auto loads the first record if minimum one record exist in table
If (Not(Is record loaded([person])))
	TRACE  // ERROR, the must be a record loaded by last "ALL RECORDS"
	LOAD RECORD([person])
End if 
If (Not(Read only state([person])))
	TRACE  // ERROR, must be read-only state
End if 
$B_Locked:=Locked([person])  // -> True (table is in read-only state, Locked function returns than always TRUE)
LOCKED BY([person];$process;$user;$sessionUser;$processName)
If (Not($B_Locked))
	TRACE  // ERROR, $B_Locked must be True (table is in read-only state...)
Else 
	  // True means always "this record can NOT modified",
	  // because record is locked by other user or other process or table is in read-only state
	If (($process=0) & ($user="") & ($sessionUser="") & ($processName=""))
		IDLE  // all is ok, this is signal for Locked returns True because table is in read-only state
	Else 
		TRACE  // record is locked by other user or other process
		  // take a look to this infos who locked it: $process; $user; $sessionUser; $processName
	End if 
End if 

READ WRITE([person])  // changes state of this one table to read/write
LOAD RECORD([person])  // when record is not locked, it gets now LOCKED by this command
If (Not(Is record loaded([person])))
	TRACE  // ERROR, record cannot loaded
	LOAD RECORD([person])
End if 
If (Read only state([person]))
	TRACE  // ERROR, must be read/write state
End if 
$B_Locked:=Locked([person])  // -> False (table is read/write and no other user/process locked the record)
LOCKED BY([person];$process;$user;$sessionUser;$processName)
If ($B_Locked)
	TRACE  // ERROR, $B_Locked must be False (table is in read/write state and record is new loaded...)
	If (($process=Current process) | ($user=Current user))
		IDLE  // record is locked by currentProcess and currentUser ???
	Else 
		IDLE  // record is locked by other user or other process ???
		  // take a look to this infos who locked it: $process; $user; $sessionUser; $processName
	End if 
Else 
	IDLE  // all is ok, Locked returns False because table is in read/write state 
	  // and this currentProcess locked successfully the record, it can now modified or deleted !!!
End if 

  // give record free
UNLOAD RECORD([person])
REDUCE SELECTION([person];0)

Your test does not test with a deleted record (read the steps in my previous code)

If you attempt to load a deleted record

Locked says False
Locked by. (process = -1)

it should be (as documented)

Locked should say True
Locked by. (process = -1)

Yes, you add it later here “deleted record” after i write and send my post,
but before you say here no word about this happens only with “deleted record”.

And yes docu says:
https://doc.4d.com/4Dv18R3/4D/18-R3/Locked.301-4901527.en.html

If you try to load a record that has been deleted, Locked continues to return TRUE. To avoid waiting for a record that does not exist anymore, use the LOCKED BY command. If the record has been deleted, the LOCKED BY command returns -1 in the process parameter.

Note: Locked returns False when there is no current record in table in other words, when Record number returns -1.


Than this is a bug in 4D or it is a mistake in documention?
There i can not help, i am to lazy too replicate this situation by deleting
after a selection was created in other process…

A Workaround can be,
test always process-number, when it is “-1”
(or no record can be loaded again)
than stop the action
this non existing record can not modified or deleted or saved…

When you need to recheck the locked status, it is important to execute the command LOAD RECORD each time. And yes checking the process number for -1 through LOCKED BY command will help determining for the existence of the record.

And yes checking the process number for -1 through LOCKED BY

Thanksfully, $process is -1 but Locked returns False, at least since 4d v15.