Click here to Skip to main content
15,913,944 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Global vs local variables Pin
Waldermort5-Sep-07 1:10
Waldermort5-Sep-07 1:10 
QuestionRe: Global vs local variables Pin
rajeevktripathi5-Sep-07 1:38
rajeevktripathi5-Sep-07 1:38 
AnswerRe: Global vs local variables Pin
jhwurmbach5-Sep-07 2:22
jhwurmbach5-Sep-07 2:22 
AnswerRe: Global vs local variables Pin
Naveen5-Sep-07 2:13
Naveen5-Sep-07 2:13 
AnswerRe: Global vs local variables Pin
David Crow5-Sep-07 4:53
David Crow5-Sep-07 4:53 
QuestionReader Writer lock Pin
Waldermort5-Sep-07 0:50
Waldermort5-Sep-07 0:50 
AnswerRe: Reader Writer lock Pin
chandu0045-Sep-07 1:42
chandu0045-Sep-07 1:42 
AnswerRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 1:52
Matthew Faithfull5-Sep-07 1:52 
There are two issues here. One is the internal gubbins of the vector class you're using. If it's the stl vector then you may be stuck as the code is essentially unreadable gibberish. The other is the synchronisation issue itself.
I use a very similar trick with a queue implemented as a linked list where one thread can remove from the queue and another append to it wihtout any blocking calls. The proviso is that there must be at least 3 items in the queue to gaurantee that the threads don't clash while they're rearraning the node pointers. My queue class itself checks this and it has never failed me. It works in practice because in low load situations where you only have on or two queue items at a time perfromance is not so critical and I can afford to switch on the locking code. I wrote this by implementing it all wiht full locking and testing it then made each locking and unlocking call conditional on swithc which is set and unset when the list size goes over the 3 item boundary. The switch itself is just a long which is incremented and decremented with the Interlocked functions.
The issue if you use someone elses underlying data structure like std::vector is that you don't know what the conditions are for it restructuring or reallocating the memory involved so this kind of scheme is risky. The activity of one thread could cause the data being access by the other to be moved even though there is no obvious overlap between what they're doing. No harm in trying it though and let me know if it works.Smile | :)

Nothing is exactly what it seems but everything with seems can be unpicked.

GeneralRe: Reader Writer lock Pin
Waldermort5-Sep-07 2:44
Waldermort5-Sep-07 2:44 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 5:02
El Corazon5-Sep-07 5:02 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 5:34
El Corazon5-Sep-07 5:34 
GeneralRe: Reader Writer lock Pin
Waldermort5-Sep-07 6:17
Waldermort5-Sep-07 6:17 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 7:38
El Corazon5-Sep-07 7:38 
GeneralRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 5:49
Matthew Faithfull5-Sep-07 5:49 
GeneralRe: Reader Writer lock Pin
Waldermort5-Sep-07 6:15
Waldermort5-Sep-07 6:15 
AnswerRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 6:28
Matthew Faithfull5-Sep-07 6:28 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 7:42
El Corazon5-Sep-07 7:42 
GeneralRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 9:30
Matthew Faithfull5-Sep-07 9:30 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 9:52
El Corazon5-Sep-07 9:52 
QuestionA very basic question Pin
HakunaMatada5-Sep-07 0:24
HakunaMatada5-Sep-07 0:24 
AnswerRe: A very basic question Pin
Matthew Faithfull5-Sep-07 0:47
Matthew Faithfull5-Sep-07 0:47 
AnswerRe: A very basic question Pin
Waldermort5-Sep-07 0:58
Waldermort5-Sep-07 0:58 
AnswerRe: A very basic question Pin
Hamid_RT5-Sep-07 1:02
Hamid_RT5-Sep-07 1:02 
QuestionIE question Pin
Mohit19825-Sep-07 0:18
Mohit19825-Sep-07 0:18 
AnswerRe: IE question Pin
Hamid_RT5-Sep-07 1:05
Hamid_RT5-Sep-07 1:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.