The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Implicit Sharing and Multi-Threading Problems

I hope this is useful to those starting to make use of multi-threading.

It appears the trolls at Qt think Implicit Sharing solves multi-thread use of framework classes. I don't think so:

http://www.folding-hyperspace.com/program_tip_15.htm

At least they need to improve their documentation. I have a feeling that most people don't know the full dangers of sharing data across threads and if you follow the advice in their documentation you will crash. Borland/Codegear's VCL uses a form of it for the AnsiString class and Qt uses it in many areas. I haven't looked specifically at MS MFC or .NET for these problems, but they possibly exist there too.

These bugs can create a crash that only happens every hour. The fact that QDateTime is shared and was not listed as so could get a novice in trouble.

When I read class values from other threads, I either use a mutex/critical-section or make sure the data is static and can be copied without problems. There is nothing wrong with reading doubles out of a thread's data space unless you rely on the value being valid all the time - in other words diagnostic or running production display use is OK.
James Gibbons Send private email
Tuesday, June 05, 2007
 
 
"Paragraphs 1, 2 and 4 appear to say it is safe to copy shared objects between threads, but paragraph 3 doesn't."

The way I read it, paragraph 3 says you can't use the same copy (instance) in multiple threads simultaneously, unless you serialize access to that copy.
dev1
Tuesday, June 05, 2007
 
 
From my understanding, they are saying that direct access from the GUI to a implicitly shared variable in another thread must be protected with a mutex, but if you copy the variable you can then access the copy all you want without problems. The purpose of my post was to show that this is not true. The second failure case I discussed would still happen in this case.
James Gibbons Send private email
Wednesday, June 06, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz