Click here to Skip to main content
14,775,570 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Global vs local variables Pin
Waldermort5-Sep-07 2:10
MemberWaldermort5-Sep-07 2:10 
QuestionRe: Global vs local variables Pin
rajeevktripathi5-Sep-07 2:38
Memberrajeevktripathi5-Sep-07 2:38 
AnswerRe: Global vs local variables Pin
jhwurmbach5-Sep-07 3:22
Memberjhwurmbach5-Sep-07 3:22 
AnswerRe: Global vs local variables Pin
Naveen5-Sep-07 3:13
MemberNaveen5-Sep-07 3:13 
AnswerRe: Global vs local variables Pin
David Crow5-Sep-07 5:53
MemberDavid Crow5-Sep-07 5:53 
QuestionReader Writer lock Pin
Waldermort5-Sep-07 1:50
MemberWaldermort5-Sep-07 1:50 
AnswerRe: Reader Writer lock Pin
chandu0045-Sep-07 2:42
Memberchandu0045-Sep-07 2:42 
AnswerRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 2:52
MemberMatthew Faithfull5-Sep-07 2: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 3:44
MemberWaldermort5-Sep-07 3:44 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 6:02
MemberEl Corazon5-Sep-07 6:02 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 6:34
MemberEl Corazon5-Sep-07 6:34 
GeneralRe: Reader Writer lock Pin
Waldermort5-Sep-07 7:17
MemberWaldermort5-Sep-07 7:17 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 8:38
MemberEl Corazon5-Sep-07 8:38 
GeneralRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 6:49
MemberMatthew Faithfull5-Sep-07 6:49 
GeneralRe: Reader Writer lock Pin
Waldermort5-Sep-07 7:15
MemberWaldermort5-Sep-07 7:15 
AnswerRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 7:28
MemberMatthew Faithfull5-Sep-07 7:28 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 8:42
MemberEl Corazon5-Sep-07 8:42 
GeneralRe: Reader Writer lock Pin
Matthew Faithfull5-Sep-07 10:30
MemberMatthew Faithfull5-Sep-07 10:30 
GeneralRe: Reader Writer lock Pin
El Corazon5-Sep-07 10:52
MemberEl Corazon5-Sep-07 10:52 
QuestionA very basic question Pin
HakunaMatada5-Sep-07 1:24
MemberHakunaMatada5-Sep-07 1:24 
AnswerRe: A very basic question Pin
Matthew Faithfull5-Sep-07 1:47
MemberMatthew Faithfull5-Sep-07 1:47 
AnswerRe: A very basic question Pin
Waldermort5-Sep-07 1:58
MemberWaldermort5-Sep-07 1:58 
AnswerRe: A very basic question Pin
Hamid_RT5-Sep-07 2:02
MemberHamid_RT5-Sep-07 2:02 
QuestionIE question Pin
Mohit19825-Sep-07 1:18
MemberMohit19825-Sep-07 1:18 
AnswerRe: IE question Pin
Hamid_RT5-Sep-07 2:05
MemberHamid_RT5-Sep-07 2: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.