Click here to Skip to main content
15,391,349 members
Home / Discussions / C#
   

C#

 
GeneralRe: Created Access DB, now how to load a list into a single column in the newly created DB. Pin
jsc426-Dec-21 2:58
professionaljsc426-Dec-21 2:58 
QuestionPass field Pin
Luis M. Rojas3-Dec-21 2:25
MemberLuis M. Rojas3-Dec-21 2:25 
AnswerRe: Pass field Pin
Richard Deeming3-Dec-21 2:56
mveRichard Deeming3-Dec-21 2:56 
Questionthread safety and performance Pin
Super Lloyd2-Dec-21 15:31
MemberSuper Lloyd2-Dec-21 15:31 
GeneralRe: thread safety and performance Pin
harold aptroot2-Dec-21 16:03
Memberharold aptroot2-Dec-21 16:03 
GeneralRe: thread safety and performance Pin
Super Lloyd2-Dec-21 17:59
MemberSuper Lloyd2-Dec-21 17:59 
AnswerRe: thread safety and performance Pin
trønderen3-Dec-21 2:36
Membertrønderen3-Dec-21 2:36 
AnswerRe: thread safety and performance Pin
trønderen3-Dec-21 3:31
Membertrønderen3-Dec-21 3:31 
Is it worth it?

Isn't that essentially a question of addressability? How many threads exist that can address the data structure at all? And do it at the same time?

I have written web servers handling one request at a time - the processing time, and traffic load, was so low that there was no reason to take the complexities of a multi-threaded server. So only a single thread was accessing the data structure, with no need to protect it.

You may have multiple threads in your code, but the other threads do other tasks; only one is accessing this structure, you are not publishing entry points or pointers to it to any other software, and if you run two instances of your code, they have individual copies of the structure? Then, no need to protect it.

You may have one startup thread building the structure, and later another working thread using it - but the first thread has completed before the second has started: They are not addressing the structure at the same time. No need to protect it.

But if there are two or more threads that may address the structure, it may happen at the same time, and a least one of these threads make modifications to the structure: Yes, then it is worth it. Especially when the implementation is as simple as you indicate, but that really shouldn't be any argument: You should protect your data from inconsistencies even if the implementation effort is above epsilon.

Runtime costs: How frequently is this data structure entered? Several times every millisecond, 24/7? Less than that? Then you can spend the time! Modern implementations of sync primitives are highly tuned code, and modern processors provide instructions to make it fast and efficient. Set up a timing loop to enter and exit your structure a million times, with and without the protection. You'd probably be surprised by how little the sync primitives add to the timing results.

Add a counter that is incremented every time you enter the structure structure, and do a few runs. If you see that the structure is entered millions of times, so the sync operations would take measurable time, then reconsider your code: Maybe you could enter the monitor to do a dozen individual operations before leaving, rather than entering and leaving a dozen times, once for each individual operation.

Admittedly, this breaks the first law of optimization: Don't do it! Depending on the state of your project, it may even break the second law of optimization: If you have to do it, don't do it yet!

Protecting data structure integrity is the other way around: If you don't have to do it, do it anyway. And: If you haven't yet done it, do it now, from the beginning!

If there is a risk of conflict, it is worth it!
QuestionUpdate/refresh Combobox in Form1 after doing an add from Form 2 Pin
Richard A Knox2-Dec-21 5:19
MemberRichard A Knox2-Dec-21 5:19 
AnswerRe: Update/refresh Combobox in Form1 after doing an add from Form 2 Pin
BillWoodruff2-Dec-21 5:58
mveBillWoodruff2-Dec-21 5:58 
GeneralRe: Update/refresh Combobox in Form1 after doing an add from Form 2 Pin
Richard A Knox4-Dec-21 6:08
MemberRichard A Knox4-Dec-21 6:08 
GeneralRe: Update/refresh Combobox in Form1 after doing an add from Form 2 Pin
Gerry Schmitz5-Dec-21 8:04
mveGerry Schmitz5-Dec-21 8:04 
QuestionReading username Pin
Luis M. Rojas1-Dec-21 4:45
MemberLuis M. Rojas1-Dec-21 4:45 
AnswerRe: Reading username Pin
lmoelleb3-Dec-21 18:36
Memberlmoelleb3-Dec-21 18:36 
QuestionHow can I make the timer stay active after the program is closed? Pin
Duke Jason30-Nov-21 19:34
MemberDuke Jason30-Nov-21 19:34 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
OriginalGriff30-Nov-21 20:09
mveOriginalGriff30-Nov-21 20:09 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
Pete O'Hanlon30-Nov-21 21:24
mvaPete O'Hanlon30-Nov-21 21:24 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
Dave Kreskowiak1-Dec-21 1:20
mveDave Kreskowiak1-Dec-21 1:20 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
Gerry Schmitz1-Dec-21 18:09
mveGerry Schmitz1-Dec-21 18:09 
QuestionCode cast InvalidCastException when it "Shouldn't" Pin
Evilfish200029-Nov-21 19:28
MemberEvilfish200029-Nov-21 19:28 
AnswerRe: Code cast InvalidCastException when it "Shouldn't" Pin
OriginalGriff29-Nov-21 21:24
mveOriginalGriff29-Nov-21 21:24 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
Evilfish200030-Nov-21 2:24
MemberEvilfish200030-Nov-21 2:24 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
OriginalGriff30-Nov-21 2:50
mveOriginalGriff30-Nov-21 2:50 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
Evilfish200030-Nov-21 22:05
MemberEvilfish200030-Nov-21 22:05 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
OriginalGriff30-Nov-21 22:19
mveOriginalGriff30-Nov-21 22:19 

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.