Click here to Skip to main content
15,891,136 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
Richard Andrew x6427-Dec-23 8:32
professionalRichard Andrew x6427-Dec-23 8:32 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads [edited] Pin
harold aptroot27-Dec-23 9:23
harold aptroot27-Dec-23 9:23 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
jschell28-Dec-23 5:55
jschell28-Dec-23 5:55 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
harold aptroot28-Dec-23 6:19
harold aptroot28-Dec-23 6:19 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
jschell29-Dec-23 4:46
jschell29-Dec-23 4:46 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
harold aptroot29-Dec-23 5:19
harold aptroot29-Dec-23 5:19 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
jschell1-Jan-24 1:59
jschell1-Jan-24 1:59 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
jschell28-Dec-23 5:54
jschell28-Dec-23 5:54 
Richard Andrew x64 wrote:
so that would lead to exceptions caused by changing the list out from under them.


That cannot happen.

Per your original description the worker threads do not modify it.

The management thread creates a new list. The worker threads never use that list until it is done and the management thread is done with it.

Richard Andrew x64 wrote:
seeing the new version of the list while other threads are still working with data from the old version of the list.


I think that requirement is going to end up requiring additional locking.

Say you look up prices in a list. Then an execution flow looks like this

Worker1: Gets price X (v1) from list.  Continues work
Management: rebuild list (simple lock)
Worker2: Starts (simple lock gone) and gets price X (v2) from list.
Worker1: Finishes work with v1
Worker2: Finishes work with v2

GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
Richard Andrew x6428-Dec-23 7:39
professionalRichard Andrew x6428-Dec-23 7:39 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
jschell29-Dec-23 4:49
jschell29-Dec-23 4:49 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
Richard Andrew x6429-Dec-23 13:25
professionalRichard Andrew x6429-Dec-23 13:25 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
jschell1-Jan-24 1:57
jschell1-Jan-24 1:57 
AnswerRe: Locking pattern to protect a critical List<> with many worker threads Pin
Gerry Schmitz27-Dec-23 8:23
mveGerry Schmitz27-Dec-23 8:23 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
Richard Andrew x6427-Dec-23 8:29
professionalRichard Andrew x6427-Dec-23 8:29 
GeneralRe: Locking pattern to protect a critical List<> with many worker threads Pin
Gerry Schmitz28-Dec-23 6:37
mveGerry Schmitz28-Dec-23 6:37 
QuestionGuides on solving this recurrence relation equation? Pin
oslon1-Dec-23 21:54
oslon1-Dec-23 21:54 
AnswerRe: Guides on solving this recurrence relation equation? Pin
Andre Oosthuizen1-Dec-23 22:12
mveAndre Oosthuizen1-Dec-23 22:12 
AnswerRe: Guides on solving this recurrence relation equation? Pin
jeron12-Dec-23 7:13
jeron12-Dec-23 7:13 
AnswerRe: Guides on solving this recurrence relation equation? Pin
jschell4-Dec-23 3:25
jschell4-Dec-23 3:25 
QuestionScheduling with constraints Pin
jedraw3-Nov-23 5:23
jedraw3-Nov-23 5:23 
AnswerRe: Scheduling with constraints Pin
Gerry Schmitz3-Nov-23 6:08
mveGerry Schmitz3-Nov-23 6:08 
AnswerRe: Scheduling with constraints Pin
Richard MacCutchan3-Nov-23 6:40
mveRichard MacCutchan3-Nov-23 6:40 
GeneralRe: Scheduling with constraints Pin
jedraw3-Nov-23 6:55
jedraw3-Nov-23 6:55 
GeneralRe: Scheduling with constraints Pin
Richard MacCutchan3-Nov-23 7:06
mveRichard MacCutchan3-Nov-23 7:06 
QuestionRound-robin tournament scheduling, with teams that may share their home field Pin
Mad Bat30-Oct-23 7:00
Mad Bat30-Oct-23 7:00 

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.