On 10/31/06, Tomasz Jankowski <[EMAIL PROTECTED]> wrote:
> wrote works fine). However I'm not sure if I should always lock and unlock
> mutex when I'm accesing some global data from thread. I know, that i'm

If the value is changing and the changes are being used to signal
between threads, then you need to have some thread synchronisation so
that the various CPU caches can get in line.

If the value doesn't change, or you don't mind if changes are not seen
by other threads for a while, then it's OK to skip the mutex.

It can sometimes be difficult to decide though. What if you skip a
mutex because you don't care about out-of-date values, and then later
change something somewhere else and those (complicated!) assumptions
break? You've got a very hard to find race condition that will
randomly crash your program.

In my opinion, the solution is to keep communication between threads
to a minimum, and where they must communicate, you keep the point of
communication small and carefully protected.

John
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to