pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

How to initialize a `ConditionVariable` in a struct when shared memory is initialized.

Open emelsimsek opened this issue 1 year ago • 2 comments

I want to initialize a ConditionVariable in a struct using ConditionVariableInit function when shared memory is initialized.

Where should this be done?

Looking into pub fn shmem_init_locked<T: Default + PGXSharedMemory>(lock: &PgLwLock<T>) {

Only T:default() is called.

emelsimsek avatar Feb 05 '24 09:02 emelsimsek

If I understand everything correctly, a way to do this at shmem-init-time is currently not exposed. At "actual" (post-init) runtime, you just call ConditionVariableInit with a pointer.

workingjubilee avatar Feb 05 '24 18:02 workingjubilee

Thank you @workingjubilee. I have called ConditionVariableInit in the main function of the worker and it seems to be ok for my case.

emelsimsek avatar Feb 06 '24 07:02 emelsimsek