Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Intentionally inconstistent use of "Atomic" in Mt.h?
Re: Intentionally inconstistent use of "Atomic" in Mt.h? [message #14239 is a reply to message #14167] Wed, 20 February 2008 19:39 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13980
Registered: November 2005
Ultimate Member
Werner wrote on Sat, 16 February 2008 11:36

luzr wrote on Sat, 16 February 2008 17:03

Well, but you should not directly assign Atomic to int, you should rather use AtomicRead...


A misunderstanding? If so, sorry for expressing the issue insufficiently!

I'm talking about the all the "Atomic..." functions in Mt.h, i. e.

AtomicDec,
AtomicInc,
AtomicRead,
AtomicWrite,
AtomicXAdd.

They all have an "Atomic&" as parameter but treat it with an "int" and/or return an "int".



First of all I think this is miniscule problem... not worthy of such detailed examination.

Anyway, notice this: The set of functions is complete. You never need to assign int directly to Atomic or back.

Imagine some platform that e.g. lacks interlocked operations. In that case you would need to simulate Atomic using mutex:

struct Atomic { Mutex lock; int value; }

There are no direct conversions to/from Atomic now... But using AtomicRead/Write and others, returning int, everything works.

Sure, things are not ideal, perhaps Atomic should rather be class from the beginning and all operations its methods....

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Distant file info
Next Topic: Checking socket connection after send.
Goto Forum:
  


Current Time: Mon May 13 13:37:04 CEST 2024

Total time taken to generate the page: 0.02008 seconds