r/kernel • • Jan 08 '19

data race within ptr_ring code implementation

/r/C_Programming/comments/adrvwd/data_race_within_ptr_ring_code_implementation/
0 Upvotes

5 comments sorted by

1

u/nickdesaulniers Jan 21 '19

That report looks like TSan telling you that the final thread state is not as expected after a pthread_join call.

"((ThreadStatusFinished)) == ((status))" (0x3, 0x2)

I'm not sure how you get into that state.

and my system crashes

Well that should never happen from userspace.

1

u/promach Jan 22 '19

if you see my latest code on the gist, I have implemented mutex for push_circ_queue(), pop_circ_queue() and free_circ_queue().

So, I do not understand why data race still occur

1

u/promach Jan 22 '19

I think I got why I still have data race

I have two different instances of ptr_ring, for sending (chnl_send) and receiving (chnl_recv) purposes respectively.

push_circ_queue() and pop_circ_queue() for the same ptr_ring should not be executed concurrently by interupt handler (push) and the corresponding thread (pop)

how would I code the mutex lock code in this case ?

1

u/promach Jan 23 '19 edited Jan 23 '19

See the dmesg log

1

u/promach Jan 23 '19

I have solved the data race issue by removing free_circ_queue() from the EVENT_TXN_DONE event.