You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "my-ship-it (via GitHub)" <gi...@apache.org> on 2025/03/10 11:22:31 UTC
Re: [PR] Fix volatile qualifier discard and ensure safe access to PGPROC in lock [cloudberry]
my-ship-it commented on code in PR #963:
URL: https://github.com/apache/cloudberry/pull/963#discussion_r1987094355
##########
src/backend/storage/lmgr/lock.c:
##########
@@ -936,19 +936,29 @@ LockAcquireExtended(const LOCKTAG *locktag,
if (lockHolderProcPtr == MyProc)
{
/* Find the guy who should manage our locks */
- PGPROC * proc = FindProcByGpSessionId(gp_session_id);
+ volatile PGPROC * proc = FindProcByGpSessionId(gp_session_id);
int count = 0;
while(proc==NULL && count < 5)
{
pg_usleep( /* microseconds */ 2000);
count++;
CHECK_FOR_INTERRUPTS();
+ /*
+ * The reason for using pg_memory_barrier() is to ensure memory ordering
+ * constraints are respected. In concurrent programming, memory barriers
+ * are used to prevent the compiler and CPU from reordering memory operations
+ * in a way that could lead to race conditions or other synchronization issues.
+ * By using pg_memory_barrier(), we can enforce a strict ordering of memory
+ * accesses, which is crucial for the correct functioning of lock mechanisms
+ * and other synchronization primitives in a multi-threaded environment.
Review Comment:
multi-threaded? or multi processes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org