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 » MT and variables simple question
Re: MT and variables simple question [message #43202 is a reply to message #43201] Fri, 06 June 2014 15:48 Go to previous messageGo to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Koldo,

As i said Quote:
if you modify a variable using the var itself or a pointer to it: the result is the same ==> you have to protect the variable


So if data10 or vars[10] are accessed by several threads you have to put :
INTERLOCKED {
    data10 = &vars[10];
}


BUT ... you have to be careful which INTERLOCK method to use:

INTERLOCKED : uses local static mutex which only protects this code (and only this one) from being accessed by several threads at same time.
INTERLOCKED(mutex) : uses the parameter mutex which allows you to protect several parts of code by calling INTERLOCKED(mutex) each time

If you only wan't to protect variables, then you probably need to use INTERLOCKED(mutex) everywhere the variable is accessed.
Here is what I mean:
// If you need to protect data10
Mutex mtx;
..
..
// in code of first thread
INTERLOCKED(mtx) {
    data10 = &vars[10];
}
..
..
// somewhere in another thread's code
INTERLOCKED(mtx) {
    data10 = xxxxx;
}


Hope I am clear enough Confused
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [SOLVED] Fix some memory leak in IpAddrInfo
Next Topic: [SOLVED][FeatureRequests]Use HttpRequest to upload large file
Goto Forum:
  


Current Time: Tue May 14 15:40:05 CEST 2024

Total time taken to generate the page: 0.03354 seconds