Should the g_once_init_enter() argument be marked as volatile?

Hello,

the documentation https://developer.gnome.org/glib/stable/glib-Threads.html#g-once-init-enter says that g_once_init_enter() and g_once_init_leave() should not be marked volatile. And, indeed, I get an incompatible pointer type warning if I declare the parameter variable as such. However, if I don’t use volatileit seems that the function does not do what it is supposed to be doing.

I am working on Tracker and I wanted to get to a warning-free build, thus I tried to remove the volatile from the declarations of g_once_init_enter() sentinel variables . However, when I do this, a lot of tests fail.

Am I misinterpreting the documentation?

Thank you.

Cheers,
Dan

Ops. Please ignore. I found the problem and it does not have to do with volatile

Glad you found the problem.

From what you’ve said, you are interpreting the documentation correctly (although I’d have to see a diff of what you’ve done to be sure). Previously, people (myself included) thought that volatile should be used to indicate a variable which is accessed atomically or by multiple threads, but that’s now understood to not be correct. volatile should basically never be used in C.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.