Click here to Skip to main content
15,886,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Thread synchronization problem Pin
samzcs11-Sep-18 2:45
samzcs11-Sep-18 2:45 
GeneralRe: Thread synchronization problem Pin
CPallini11-Sep-18 3:23
mveCPallini11-Sep-18 3:23 
AnswerRe: Thread synchronization problem Pin
leon de boer10-Sep-18 22:08
leon de boer10-Sep-18 22:08 
GeneralRe: Thread synchronization problem Pin
samzcs11-Sep-18 2:50
samzcs11-Sep-18 2:50 
GeneralRe: Thread synchronization problem Pin
leon de boer11-Sep-18 5:05
leon de boer11-Sep-18 5:05 
GeneralRe: Thread synchronization problem Pin
11917640 Member 11-Sep-18 19:53
11917640 Member 11-Sep-18 19:53 
GeneralRe: Thread synchronization problem Pin
samzcs12-Sep-18 8:12
samzcs12-Sep-18 8:12 
GeneralRe: Thread synchronization problem Pin
leon de boer12-Sep-18 18:31
leon de boer12-Sep-18 18:31 
It isn't at all surprising it misbehaves you have >>>> SHARED DATA <<<<

You guys seem to think having a co-operative task switcher somehow makes you
immune to shared data issues ... well your wrong as you found out Smile | :)

lets give you the situation .. it may not be your case but follow what happens

task b picks up the count of the recieve buffer .. then yields to task a
task a changes the count value of the recieve buffer then yields back to task b
task b now wrongly writes the old count value back and your program now crashes

So the variable "count" is being accessed by both tasks it is shared, it is that simple

The same will be true of other variables you are accessing with both taskA and taskB
and if you drag all the stuff accessed by both tasks to an area they are called the
shared data and they are the problem.

Now what creates the problem above is yielding between the two tasks, while one task
is using the shared data.

Now on the code above it looks like taskB probably never yields while it is inside dataCB.
That is because it's a function and I doubt you can organize the yield.

However on your taskA code above which looks like it in a flat loop you also can not yield
to taskB anywhere in it not even in the "..." section. It must start and finish that entire
code without ever yielding to taskB or your code will crash. The hint to why it would crash
is the variable rcvd which is probably a bool and it's written to by both tasks a big no no
or danger Will Robinson, as per the example I gave at top.

If you understoof the issue you can refactor taskA code to make the problem less likely but
curing it if you want to yield in "..." needs definitive steps.

anyhow I will leave you with it.
In vino veritas


modified 13-Sep-18 1:03am.

GeneralRe: Thread synchronization problem Pin
11917640 Member 12-Sep-18 18:58
11917640 Member 12-Sep-18 18:58 
AnswerRe: Thread synchronization problem Pin
«_Superman_»23-Sep-18 22:26
professional«_Superman_»23-Sep-18 22:26 
QuestionBreak when address reading Pin
Member 130813699-Sep-18 15:47
Member 130813699-Sep-18 15:47 
AnswerRe: Break when address reading Pin
Victor Nijegorodov10-Sep-18 2:04
Victor Nijegorodov10-Sep-18 2:04 
GeneralRe: Break when address reading Pin
Member 1308136910-Sep-18 15:45
Member 1308136910-Sep-18 15:45 
AnswerRe: Break when address reading Pin
leon de boer10-Sep-18 2:12
leon de boer10-Sep-18 2:12 
GeneralRe: Break when address reading Pin
Member 1308136910-Sep-18 15:49
Member 1308136910-Sep-18 15:49 
AnswerRe: Break when address reading Pin
Richard Andrew x6410-Sep-18 8:17
professionalRichard Andrew x6410-Sep-18 8:17 
GeneralRe: Break when address reading Pin
Member 1308136910-Sep-18 15:50
Member 1308136910-Sep-18 15:50 
AnswerRe: Break when address reading Pin
«_Superman_»23-Sep-18 22:30
professional«_Superman_»23-Sep-18 22:30 
Questionconfusion about fonts in Windows Pin
Alexander Kindel6-Sep-18 8:43
Alexander Kindel6-Sep-18 8:43 
AnswerRe: confusion about fonts in Windows Pin
leon de boer6-Sep-18 17:12
leon de boer6-Sep-18 17:12 
GeneralRe: confusion about fonts in Windows Pin
Alexander Kindel6-Sep-18 18:21
Alexander Kindel6-Sep-18 18:21 
GeneralRe: confusion about fonts in Windows Pin
leon de boer7-Sep-18 8:41
leon de boer7-Sep-18 8:41 
GeneralRe: confusion about fonts in Windows Pin
Alexander Kindel11-Sep-18 13:24
Alexander Kindel11-Sep-18 13:24 
AnswerRe: confusion about fonts in Windows Pin
Richard Andrew x649-Sep-18 8:17
professionalRichard Andrew x649-Sep-18 8:17 
GeneralRe: confusion about fonts in Windows Pin
leon de boer9-Sep-18 18:04
leon de boer9-Sep-18 18:04 

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.