Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #14380

Some doubts about Mutex

Date 2012-02-21 16:52 +0100
From Willy <gruppi@willygroup.org>
Newsgroups comp.lang.c++
Subject Some doubts about Mutex
Message-ID <4f43bdbd@extreme.x-privat.org> (permalink)
Organization X-Privat.Org NNTP Server - http://www.x-privat.org

Show all headers | View raw


Hi,
I've just started to study parallel programming on Linux and I've 
already some doubts about Mutex.

I've a generic data, which I want to access with mutually exclusion 
(1read or 1read).

data

Then I've read/write method:
read_data(...), write_data(...)

Then I've other two method like:

operation_1(...)
{
	...
	operation_2(...)
	...
}

operation_2(...)
{
	...
	read_data(...)		//[1]
	...
	write_data(...)		//[2]
	...
}


Initially I had put between mutex only the read_data and write_data 
methods, then I've realized that this way can bring some trouble because 
if some process/thread call operation_2, some other process/thread can 
call write_data between [1] and [2] screwing up all.

Which is the better way to solve this situation?

Thanks
-- 
*Willy* - *Contatti*: http://snipurl.com/contatti
* *FAQ* di /it-alt.comp.software.mozilla/: http://www.FAQmozilla.org
* *Gratuiki* - Software Free: http://gratuiki.willygroup.org

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Some doubts about Mutex Willy <gruppi@willygroup.org> - 2012-02-21 16:52 +0100
  Re: Some doubts about Mutex Paavo Helde <myfirstname@osa.pri.ee> - 2012-02-21 23:58 -0600

csiph-web