Re: Question about multithreads



Tomasz Jankowski wrote:
I generaly know how to write multithreads applications (so far code, which I
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
obligated to sorround with mutex's lock and unlock each part of code, which
acces some global variables, but I wonder if I can omit mutex locking when I
do such fast thing like reading drom integer variable. Can I do it?

AFAIK, integer reading is atomic.  So you probably can since mutex locking
probably indicates you just protect against write-in-the-middle case, not
performing any synchronization.

Paul




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]