Click here to Skip to main content
13,796,423 members

C / C++ / MFC

 
AnswerRe: Thread synchronization problem Pin
samzcs11-Sep-18 3:45
membersamzcs11-Sep-18 3:45 
GeneralRe: Thread synchronization problem Pin
CPallini11-Sep-18 4:23
mvpCPallini11-Sep-18 4:23 
AnswerRe: Thread synchronization problem Pin
leon de boer10-Sep-18 23:08
memberleon de boer10-Sep-18 23:08 
GeneralRe: Thread synchronization problem Pin
samzcs11-Sep-18 3:50
membersamzcs11-Sep-18 3:50 
GeneralRe: Thread synchronization problem Pin
leon de boer11-Sep-18 6:05
memberleon de boer11-Sep-18 6:05 
GeneralRe: Thread synchronization problem Pin
11917640 Member 11-Sep-18 20:53
member11917640 Member 11-Sep-18 20:53 
GeneralRe: Thread synchronization problem Pin
samzcs12-Sep-18 9:12
membersamzcs12-Sep-18 9:12 
GeneralRe: Thread synchronization problem Pin
leon de boer12-Sep-18 19:31
memberleon de boer12-Sep-18 19: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 19:58
member11917640 Member 12-Sep-18 19:58 
AnswerRe: Thread synchronization problem Pin
«_Superman_»23-Sep-18 23:26
professional«_Superman_»23-Sep-18 23:26 
QuestionBreak when address reading Pin
Member 130813699-Sep-18 16:47
memberMember 130813699-Sep-18 16:47 
AnswerRe: Break when address reading Pin
Victor Nijegorodov10-Sep-18 3:04
memberVictor Nijegorodov10-Sep-18 3:04 
GeneralRe: Break when address reading Pin
Member 1308136910-Sep-18 16:45
memberMember 1308136910-Sep-18 16:45 
AnswerRe: Break when address reading Pin
leon de boer10-Sep-18 3:12
memberleon de boer10-Sep-18 3:12 
GeneralRe: Break when address reading Pin
Member 1308136910-Sep-18 16:49
memberMember 1308136910-Sep-18 16:49 
AnswerRe: Break when address reading Pin
Richard Andrew x6410-Sep-18 9:17
professionalRichard Andrew x6410-Sep-18 9:17 
GeneralRe: Break when address reading Pin
Member 1308136910-Sep-18 16:50
memberMember 1308136910-Sep-18 16:50 
AnswerRe: Break when address reading Pin
«_Superman_»23-Sep-18 23:30
professional«_Superman_»23-Sep-18 23:30 
Questionconfusion about fonts in Windows Pin
Alexander Kindel6-Sep-18 9:43
memberAlexander Kindel6-Sep-18 9:43 
AnswerRe: confusion about fonts in Windows Pin
leon de boer6-Sep-18 18:12
memberleon de boer6-Sep-18 18:12 
GeneralRe: confusion about fonts in Windows Pin
Alexander Kindel6-Sep-18 19:21
memberAlexander Kindel6-Sep-18 19:21 
GeneralRe: confusion about fonts in Windows Pin
leon de boer7-Sep-18 9:41
memberleon de boer7-Sep-18 9:41 
GeneralRe: confusion about fonts in Windows Pin
Alexander Kindel11-Sep-18 14:24
memberAlexander Kindel11-Sep-18 14:24 
AnswerRe: confusion about fonts in Windows Pin
Richard Andrew x649-Sep-18 9:17
professionalRichard Andrew x649-Sep-18 9:17 
GeneralRe: confusion about fonts in Windows Pin
leon de boer9-Sep-18 19:04
memberleon de boer9-Sep-18 19: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.


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.181207.3 | Last Updated 12 Dec 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid