Set the queue handle to null before stop & destroy. (#525) 45/208345/1 accepted/tizen/unified/20190626.040955 submit/tizen/20190625.065348 submit/tizen/20190625.235330
authorsenthil.gs@samsung.com <senthil.gs@samsung.com>
Thu, 20 Jun 2019 14:02:45 +0000 (19:32 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 24 Jun 2019 00:49:51 +0000 (09:49 +0900)
commitd919583a1e1bd42ade7137140c92ec3db13c9c85
treebe18e4c8d9b43cc0656822a39f8eb314f452ed1c
parent29c1fca0c716c0d5846d97ca3c05deefe8c7ef47
Set the queue handle to null before stop & destroy. (#525)

g_sendQueueHandle is set to NULL to prevent new requests from being enqueued.
It avoids a race condition which could occur when adding elements to QueueingThread if it's already stopped.

Race condition scenario:-
Background:-
-> If a thread has called CAQueueingThreadStop(), it signals the condition variable
to wake up the CAQueueingThreadBaseRoutine.

-> After signaling, it waits on the same condition variable
to wait for the completion of CAQueueingThreadBaseRoutine.

-> CAQueueingThreadBaseRoutine will finish its current task and signals the condition variable.

-> CAQueueingThreadStop should wake up upon signal and return back to caller.

Issue:-
-> CAQueueingThreadAddData also signals the condition variable which can wake up the thread that called CAQueueingThreadStop.
-> CAQueueingThreadStop returns back to caller assuming that the CAQueueingThreadBaseRoutine has stopped. But it could still be running.

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/525
(cherry picked from eb98e19b49ab4d4475449f99f3a4a53607dbea01)

Change-Id: I5b22c034b30b00fc1ae7f08c37c278c29910345c
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c