atomic operation

Hi,

 Is it official to say that fetching and storing a 'long' (for 32-bit
and 64-bit) is an atomic operation ?

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
guy
10/29/2004 2:33:59 PM
comp.lang.c++.moderated 10705 articles. 11 followers. allnor (8507) is leader. Post Follow

12 Replies
280 Views

Similar Articles

[PageSpeed] 27
"Guy" <guy.peleg@gmail.com> wrote in message
news:f4d01807.0410280800.4c62b16a@posting.google.com...

>  Is it official to say that fetching and storing a 'long' (for 32-bit
> and 64-bit) is an atomic operation ?

absolutely not.



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Balog
10/31/2004 10:51:54 AM
guy.peleg@gmail.com (Guy) wrote in message 
news:<f4d01807.0410280800.4c62b16a@posting.google.com>...
> Hi,
> 
>  Is it official to say that fetching and storing a 'long' (for 32-bit
> and 64-bit) is an atomic operation ?
> 

No

joshua lehrer
factset research systems
NYSE:FDS

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
usenet_cpp
10/31/2004 10:54:22 AM
Guy wrote:
> Hi,
> 
>  Is it official to say that fetching and storing a 'long' (for 32-bit
> and 64-bit) is an atomic operation ?
>   peri
There's no C++ concept of atomic operations.   You'll have to
check your particular implementation for such support.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Ron
10/31/2004 10:54:43 AM
On 29 Oct 2004 10:33:59 -0400, guy.peleg@gmail.com (Guy) wrote in
comp.lang.c++.moderated:

> Hi,
> 
>  Is it official to say that fetching and storing a 'long' (for 32-bit
> and 64-bit) is an atomic operation ?

No, it is not.  Accesses of the type 'sig_atomic_t', defined in
<csignal> or <signal.h> are guaranteed to be atomic operations.  In
theory this could be an 8-bit type on 8-bit processors, but there
isn't much C++ activity on 8-bit processors these days.

In most cases it is signed or unsigned int, but there is no guarantee.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Jack
10/31/2004 11:16:03 AM
On 29 Oct 2004 10:33:59 -0400, Guy <guy.peleg@gmail.com> wrote:

>  Is it official to say that fetching and storing a 'long' (for 32-bit
> and 64-bit) is an atomic operation ?

I presume, you are talking atomic with regards to threads, right?

If so, then no, it's not. There are too many processor dependent factors  
involved.

On processors that work with aligned data only it's atomic only when  
reading and writing a machine word on machine instruction level, that is,  
the instruction is atomic and can't be interrupted in the middle. For 32  
bit processors the machine word is most likely also a 32-bit int. On  
processors which do work with unaligned data (like x86 does), it's only  
atomic when accessing properly aligned data.

But the machine instruction level atomicity buys you little in multithread  
code. The reason being memory visibility, that is, instruction atomicity  
does not imply that a written to memory value will immediately be seen by  
other threads on a multiprocessor, which is pretty much what you want.  
This is because all modern processors cache memory, writes go to cache,  
cache gets flushed to memory at arbitrary from code's point of view  
moments, other processors may know of the new value only when it has been  
written to memory. So, there must be a means to flush writes to memory and  
to signal other processors to update their cashes. This means are provided  
by memory barriers, that ensure that the effect of invoking them is that  
all other threads will see changes to memory made before invoking the  
memory barrier.

Operating systems provide memory barriers as function calls. For POSIX you  
can find a list of functions that issue the memory barrier here  
http://groups.google.com/groups?selm=opsf9kv0mjti5cme%40localhost.localdomain&rnum=2&filter=0.  
For win32 you may start looking here  
http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/synchro_88127404-a394-403f-a289-d61c45ab81d5.xml.asp


-- 
Maxim Yegorushkin

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Maxim
10/31/2004 11:18:33 AM
Maxim Yegorushkin wrote:
[...]
> Operating systems provide memory barriers as function calls. For POSIX you
> can find a list of functions that issue the memory barrier here
> 
http://groups.google.com/groups?selm=opsf9kv0mjti5cme%40localhost.localdomain&rnum=2&filter=0.

In addition to the links I've posted in my previous message, see
also <http://cmc.rice.edu/docs/docs/Adv1999Mar1RecentAdva.pdf>.

regards,
alexander.

P.S. DRB it totally wrong with respect to {non}conformance of
release consistency model, BTW.

--
"The current POSIX memory model is far from perfect. [...] I 
 really think you'd be far better off persuing this at the C++ 
 language level and lobbying for a language threading model that 
 can coexist with (carefully designed) POSIX implementations but 
 is not directly dependent on the POSIX language."

   -- DRB (sorta annoyed by pseudo-C++ illustrations ;-) )

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Alexander
11/2/2004 9:38:33 PM
Jack Klein wrote:
[...]
> >  Is it official to say that fetching and storing a 'long' (for 32-bit
> > and 64-bit) is an atomic operation ?
> 
> No, it is not.  Accesses of the type 'sig_atomic_t', defined in
> <csignal> or <signal.h> are guaranteed to be atomic operations.  

Only with respect to assignments in signal handlers (when this
or that signal is delivered to the same thread and only for static 
volatile sig_atomic_t objects). It has really nothing to do with 
threads (just in case you meant to imply that) Uhmm, see 
<http://tinyurl.com/5zvyj>. Better read this entire thread 
<http://tinyurl.com/5g6pm>... you might as well contribute. ;-)

regards,
alexander.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Alexander
11/2/2004 9:40:03 PM
Thanks but I think I need to rephrase the question. 

Suppose I have a 'long'(in either 32-bit or 64-bit) I have a process
with two threads. One is reading this 'long' and one is writing it. Is
it possible that while the writing thread is in the middle of the
writing, the process will switched to the reading thread? Or is it
true to say that this action (updating or reading) this long is safe?

Alexander Terekhov <terekhov@web.de> wrote in message news:<4187AF6B.E09C3A11@web.de>...
> Maxim Yegorushkin wrote:
> [...]
> > Operating systems provide memory barriers as function calls. For POSIX you
> > can find a list of functions that issue the memory barrier here
> > 
> http://groups.google.com/groups?selm=opsf9kv0mjti5cme%40localhost.localdomain&rnum=2&filter=0.
> 
> In addition to the links I've posted in my previous message, see
> also <http://cmc.rice.edu/docs/docs/Adv1999Mar1RecentAdva.pdf>.
> 
> regards,
> alexander.
> 
> P.S. DRB it totally wrong with respect to {non}conformance of
> release consistency model, BTW.
> 
> --
> "The current POSIX memory model is far from perfect. [...] I 
>  really think you'd be far better off persuing this at the C++ 
>  language level and lobbying for a language threading model that 
>  can coexist with (carefully designed) POSIX implementations but 
>  is not directly dependent on the POSIX language."
> 
>    -- DRB (sorta annoyed by pseudo-C++ illustrations ;-) )

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
guy
11/8/2004 11:36:46 PM
guy.peleg@gmail.com (Guy) wrote in message
news:<f4d01807.0411072321.719f19e2@posting.google.com>...

 > Thanks but I think I need to rephrase the question.

 > Suppose I have a 'long'(in either 32-bit or 64-bit) I have a process
 > with two threads. One is reading this 'long' and one is writing it. Is
 > it possible that while the writing thread is in the middle of the
 > writing, the process will switched to the reading thread? Or is it
 > true to say that this action (updating or reading) this long is safe?

It's not possible to say anything.

I think your missing what most of the posters have been trying to tell
you.  Atomicity is not necessarily relevant.  You speak of switching
threads, for example.  But on many machines today, there are two or more
threads running simultaneously -- no thread switch is necessary for
problems to occur, and the issue is not just atomicity, but visibility.
On most machines, a thread switch can only occur on an instruction
boundary -- Intel processors have an increment memory instruction, and
if thread switching on a single processor were the only issue, that
would suffice for an atomic increment.  It doesn't, and it is not
without reason that processors have additional hardware synchronization
means; even 25 years ago, Intel required a LOCK prefix on an increment
in memory, if you wanted the operation to be atomic, and the plethory of
caches and pipelines in a modern processor just makes the issue more
complex.

Under Posix, the rule is simple: if any thread modifies, all accesses
must be serialized by means of one of the system locking mechanisms
(mutex, semaphore, etc.).  I suspect that the rule under Windows is the
same.  On the other hand, many systems provide additional, system
specific methods of serialization or synchronization, and in most cases,
if you're not afraid of a little assembler, you can avoid the system
synchronizations in specific cases.  (On both Sparc and Intel 32 bit
architectures, this involves special machine instructions that are never
generated by the compiler.)

If all you mean is that if you have a long with 0, and one thread writes
0xFFFFFFFF, then other threads can never see anything but 0 or
0xFFFFFFFF (and not, for example, 0xFFFF0000 or 0x0000FFFF), then the
answer still depends on the processor and the alignement of the data.
And theoretically, at least, it is possible that the other thread never
see the change unless you do something special.

--
James Kanze           GABI Software         http://www.gabi-soft.fr
Conseils en informatique orient�e objet/
                    Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
kanze
11/9/2004 12:22:19 PM
guy.peleg@gmail.com (Guy) wrote in message news:<f4d01807.0411072321.719f19e2@posting.google.com>...
 > Thanks but I think I need to rephrase the question.
 >
 > Suppose I have a 'long'(in either 32-bit or 64-bit) I have a process
 > with two threads. One is reading this 'long' and one is writing it. Is
 > it possible that while the writing thread is in the middle of the
 > writing, the process will switched to the reading thread? Or is it
 > true to say that this action (updating or reading) this long is safe?

There are no guarantees in C++, whether longs are 32, 33 or 64 bits.
Of course, there are no threads in C++, so this usually doesn't
matter. Once you use a threading extension to C++, that extension
should tell you - and you should ask your question in a group which
covers that extension.

Regards,
Michiel Salters

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Michiel
11/9/2004 12:22:48 PM
Guy wrote:
 > Thanks but I think I need to rephrase the question.
 >
 > Suppose I have a 'long'(in either 32-bit or 64-bit) I have a process
 > with two threads. One is reading this 'long' and one is writing it. Is
 > it possible that while the writing thread is in the middle of the
 > writing, the process will switched to the reading thread? Or is it
 > true to say that this action (updating or reading) this long is safe?
<snip>

This is unanswerable without knowing the details of the running
environment (OS, processor architecture, library implementation...).
Multithreaded programs are outside the scope of the C++ standard.

-- 
Ben Hutchings
If God had intended Man to program,
we'd have been born with serial I/O ports.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Ben
11/9/2004 12:27:01 PM
guy.peleg@gmail.com (Guy) wrote
> Thanks but I think I need to rephrase the question. 
> 
> Suppose I have a 'long'(in either 32-bit or 64-bit) I have a process
> with two threads. One is reading this 'long' and one is writing it. Is
> it possible that while the writing thread is in the middle of the
> writing, the process will switched to the reading thread? Or is it
> true to say that this action (updating or reading) this long is safe?

I don't think you've asked anything here that wasn't assumed the first
time around. In any case, the answer doesn't change: it's still NO.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
allan_w
11/9/2004 9:11:44 PM
Reply:
Similar Artilces:

How to search for an atom in another atom
Hi folks, I just started to learn Lisp, and I have a small question: I have to write a function which checks if an atom is contained in another atom. For example: >(setf expr 'xyz) XYZ > (checkp 'x expr) T >(checkp 'a expr) NIL Unfortunately I have no clue how I can access the single "chars" of an atom. And it is kind of hard to find this information if you don't know for which function to search. Could somebody give me a hint? Thanks in advance, Christian Christian Soltenborn <no_spam_csoltenborn@webmail.de> writes: > Unfortunately I hav...

Pairwise Operation
Hi, I am trying to perform pairwise comparisons of all elements in a vector. Is there a way to do this without looping? More specifically I have a bunch of points {p_1,...,p_n} in R^m and want to create an affinity matrix A where A_ij = affinity(p_i,p_j) where affinity(x,y) just measures a distance between points x and y. Thanks. -Irvin H. irvin.hwang wrote: > > > Hi, > > I am trying to perform pairwise comparisons of all elements in a > vector. Is there a way to do this without looping? More > specifically > I have a bunch of points {p_1,...,p_n} in R^m and wa...

odd behaviour of overloaded * operator
Hi, I've created a class and defined how it should multiply with the other number classes, but I keep getting errors when using it. Recently I spotted that the errors came when I used: double * myClass as opposed to: myClass * double Can someone tell me how I should be overloading my operators to avoid the above problem? <Cleverbum@hotmail.com> wrote in message news:1149350334.678230.207250@j55g2000cwa.googlegroups.com... > Hi, > I've created a class and defined how it should multiply with the other > number classes, but I keep getting errors when using it. Recen...

Atomic Object is hiring
Atomic Object has been an XP/Agile shop since its beginning in 2001. We're looking to hire a couple good developers this summer. Specifics can be found at this blog post... http://spin.atomicobject.com/2007/06/18/were-hiring-this-summer/ ...

acquire barrier for atomic reference counting
It seems to be the conventional wisdom here (http://tinyurl.com/ 4oyh6k, for example) and elsewhere (see "4.3: Reference counting" at http://tinyurl.com/3eklht) that when doing basic threadsafe reference counting of shared objects (not talking about unprotected shared pointers here, though) that you need a release semantics for reference count decrements, except in the case that the count is now zero, in which case you need acquire semantics. Here I'm talking about a straightforward reference counting implementation, where the pointer implementation looks something like...

OT: high-accuracy atomic clock to be attached outside of the International Space Station
....an agreement that paves the way for the launch of a high-accuracy atomic clock to be attached to the outside of the European Columbus laboratory onboard the International Space Station (ISS). See more: http://www.esa.int/esaCP/SEMRDI9K73G_index_0.html David On 2009-12-15, David J Taylor <david-taylor@blueyonder.delete-this-bit.and-this-part.co.uk.invalid> wrote: > ...an agreement that paves the way for the launch of a high-accuracy > atomic clock to be attached to the outside of the European Columbus > laboratory onboard the International Space Station...

US-TX-San Antonio: Operations Analyst, BMC Control-M
US-TX-San Antonio: Operations Analyst, BMC Control-M - 3 to 5 years experience p (45303432408) ============================================================================================== Position: Operations Analyst Reference: JGG00089 Location: San Antonio TX Duration: c-p Skills: BMC Control-M: 3 to 5 years experience performing job scheduling and product administration. Working knowledge of client-server and Internet infrastructure in a Microsoft Windows 2000 environment. Excellent verbal and writt...

FAQ 7.7 Why do Perl operators have different precedence than C operators? #6 228503
This is an excerpt from the latest version perlfaq7.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 7.7: Why do Perl operators have different precedence than C operators? Actually, they don't. All C operators that Perl copies have the same precedence in Perl as they do in C. The problem is with operators that ...

[OT]: Microsoft tries to patent a BASIC operator
http://www.eweek.com/article2/0,1759,1766949,00.asp -- OpenVMS - The classics never go out of style. As Gates and Paul Allen have admitted that they based the first Microsoft BASIC on DEC's BASIC Plus and reverse engineered the DEC compiler (fun with DDT) to help them this attempt to patent an IsNot operator is ridiculous. Paul Allen still runs a public access DEC TOPS-20 system (maybe TOPS-10 as well) on the net and freely admits DEC's influence on early Microsoft code. -- Alan Greig As Gates and Paul Allen have admitted that they based the first Microsoft BASIC on DEC's...

Unknown operator
Hi, can someone tell me what operator is and what does the operator in the following example? x | ------- | f(x) It should be a variant of a division but I don't know in what way it's different. Thanks in advance for any help. On Mon, 21 Sep 2009 21:33:01 +0200, "4N" <xxx@yyy.com> wrote: >Hi, > >can someone tell me what operator is and what does the operator in the >following example? > > x | >------- >| f(x) > >It should be a variant of a division but I don't know in what way it's >different. >Thanks...

Atom
Goor morning, Is there a relevant newsgroup interested in the Acorn Atom ? Thank you for your help. Guy -- xxx@genista.net xxx=guy In article <43eaf814$0$29185$8fcfb975@news.wanadoo.fr>, Genista <genistafrance@wanadoo.fr> wrote: > Goor morning, > Is there a relevant newsgroup interested in the Acorn Atom ? This is it - or others in the csa hierarchy. There may not be many currently using the machine so you may have to depend on readers' memories! ;-) -- John Cartmell john@ followed by finnybank.com 0845 006 8822 Qercus magazine FAX +44 (0)8700-519-527 www....

-55 degree operation and micros
I've got lot's of circuits that will work at -40 degrees. what does everyone here do for -55 degrees C? If I go to MIL temp components I'm very limited on microprocessor choices; is a heater the way to go to bring the internal temp up to -40 and still use industrial components? Thanks all "BE" <me@m.com> wrote in message news:Fpxjb.3645$%B2.2449158@news4.srv.hcvlny.cv.net... > I've got lot's of circuits that will work at -40 degrees. what does everyone > here do for -55 degrees C? If I go to MIL temp components I'm very limited > on micropro...

Exponentiation operator
How is the operator ** implemented? Is it something like this: x**y = exp (y * log(x))? If the degrees are integer, does it work faster if exponentiation is replaced by multiplication where possible? E.g., in the expression of the Lennard-Jones potential y = x**12 - x**6 is it reasonable (in order to improve performance) to rewrite this expression as follows: x2 = x * x x4 = x2 * x2 x6 = x2 * x4 x12 = x6 * x6 y = x12 - x6 <s8ngsu3@yahoo.com> wrote in message news:1151764494.265581.109710@p79g2000cwp.googlegroups.com... > If the degrees are integer, does it work faster if exponen...

US-FL-Eglin AFB: Systems Test Engineer, Development/operational testing, DCGS; C (45285257607)
US-FL-Eglin AFB: Systems Test Engineer, Development/operational testing, DCGS; C (45285257607) ============================================================================================== Position: Systems Test Engineer Reference: SMC01154 Location: Eglin AFB FL Duration: C-P Skills: An Air Force intelligence background with experience in developmental and/or operational testing. Experience in the Digital Common Ground Station (DCGS) testing, and the Intelligence Imagery Laboratory. Please send your current resume...

Looping operations on Rows
Hi Is there a way that I could do iterative operations on rows ( records) . As arrays in SAS are operating on colums , how can I incoporate ( say a do or a for loop ) that I could have used in C language for doing an iterative operation . Cheers Aj ...

Noob ? about Transpose and List Operations
Hi! I'm trying to transpose a matrix B, In[61]:= B' = MatrixForm[Transpose[B]] and instead of getting the transpose, I get as output the same matrix B with two brackets and the word "Transpose" surrounding it. This is highly unhelpful ;-) What am I doing wrong? Thanks! Tarah wrote: > Hi! I'm trying to transpose a matrix B, > > In[61]:= B' = MatrixForm[Transpose[B]] > > and instead of getting the transpose, I get as output the same matrix B with two brackets and the word "Transpose" surrounding it. This is highly un...

Sobel operator for direction finding
Hi, I am trying to find the directional field of an image by computing the direction of its edges. I understand applying the two sobel operators i would get the gradient along the X(Gx) and Y(Gy) directions. When i compute arctan(Gy/Gx) for a particular picxel i get an angle O. 1.What is the physical interpretation of this angle O? 2.From what i know, this angle O is supposed to be perpendicular to the direction of the edge but when i compute it for a 3x3 neighbourhood(located on the edge) it does not seem to be perpendicular to the edge. Why is this so? 3.This angle O is pertinent only to ...

ACORN ATOM
REM THE 4 ACORNS DIM VV9;F.A=0TO9;VVA=-1;N. P."247 BYTES OPCODE, STARTING AT:"' IN.P; Q=P P."BUSY..."' P.$21 GOS.a;GOS.a P.$6 @=0 P."START PROGRAM WITH 'LINK #"&Q"'."' P."PRESS CTRL-1/2/3/4"' END aP=Q;[ LDA #209 CMP @VV1/256 BEQ VV0 STA #28EE LDA #208 STA #28ED LDA @VV1/256 STA #209 LDA @VV1&255 STA #208 :VV0 RTS :VV1 PHP CMP @#15 BCS VV2 CMP @#11 BCC VV2 ...

* and / using same step operation!!
hi some forth code for demonstration of ringfield number theory applied to reducing the size of divide multiply operations. c*/ is the basic operation which both will do divide and multiply ... ( ringfield demo ) Code dont ( exit no restore for /step ) RI RI FE BA End-Code : /step >r 2* r@ + cskip dont r@ negate u+ r> BA ; : c*/ /step /step /step /step /step /step /step /step drop ; \ character mul div support, safe to 7 bit, and most 8 bit sets : c* ( c1 c2 -- c1*c2 ) $8000 + swap invert u2*8 swap c*/ ; : c/ ( c1 c2 -- rem*256+quot ) negate cl...

Improving my atoms.
I've got a project I've been affectionately referring to as my "lisp chicken scratch". And I want to improve the design with regard to the atoms. Currently I'm using a 32-bit word as a 2-bit tag and 30-bit value, which for an atom is interpreted as 5 6-bit codes from this set: " ABCDEFG HIJKLMNO PQRSTUVW XYZ_abcd efghijkl mnopqrst uvwxyz)1 2345 6789" But, I'm not sure that I actually need 2 cases of alphabet in there. Don't most lisps fold lowercase to upper internally? If I cut the alphabet in half, I can fit 6 5-bit codes in 30-bits...

operator |=
Hi people, Did I dream about an opeartor |=? I can't find any reference to it in the online docs, yet I think I've seen it in some samples. What does it do? TIA -- Fernando Cacciola SciSoft http://fcacciola.50webs.com You might be thinking about ||=3D ||=3D assigns a value to a variable if the variable is nil e.g.=20 x =3D 5 x ||=3D 88 x #=3D> 5 y =3D nil y ||=3D 88 y # =3D> 88 I believe a |=3D b "ORs" the bits in a and b and assigns them to a -----Original Message----- From: news [mailto:news@ger.gmane.org] On Behalf Of Fernando Cacciola Sent: Tue...

can member operators be virutal? does it make sense?
I have never seen this in practice and interested in its pros, or ever existential (another words, standardized) possibility? Thanks, Sasha puzzlecracker wrote: > I have never seen this in practice and interested in its pros, or ever > existential (another words, standardized) possibility? As far as I know it's standardised - this works exactly as you'd expect: #include <iostream> class Foo { public: virtual void operator()(const int& a) { std::cout << "Foo" << std::endl; } }; class Bar : public Foo { public: virtual void operator()(...

Cogent presentations slow after many hours of Matlab/Cogent operation
Hi, I'm running visual presentation experiments using the Cogent toolbox. I'm wondering why my experiment slows after Matlab has been running for a few hours. This problem can be fixed by restarting the computer. I'm not sure if it can also be fixed by restarting Matlab (I've created the program for a colleague). This can occur spontaneously or after the program has maintained the same display for a few minutes waiting for a response: cflip waitkeydown(inf); This occurs after the experiment has run many times at normal speed. Each time a new experiment is run the Coge...

Problem about overload operator ++
This is a program just for testing operator overloading. But I found the operator ++ doesn't act like on built-in types. For detail: When int array[10]; Ptr_to_T<int> smart_ptr(&array[0], array, 10); *smart_ptr++ = 10; // I want to modify array[0],but this sentence modifies array[1] Do I make myself clear? Could some body tell me how to fix it ? #include <iostream> using namespace std; template<typename T> class Ptr_to_T { public: Ptr_to_T(T* p, T* array, int size):_p(p),_array(array),_size(size) {} Ptr_to_T(T* p):_p(p){} Ptr_to_T& opera...

Error: Unexpected MATLAB operator
I am receiving the above error when I try to run the following code in Matlab 2008a. I cannot figure out why. Any information would be most useful: % Select Image [filename, pathname] = uigetfile('*.tif','TIF-files (*.tif)'); I = imread(filename, 'tif'); %compute image threshold level = graythresh(I); BW = im2bw(I,level); imshow(BW) % user selects starting point for tidemark [x,y] = getpts(gcf); x = round(x); y = round(y); % determines coordinates along trace [sp_x,Tidemark]=contour_trace(BW,y,x); imshow(Tidemark) Usually when an error occurs, the offending line i...