views:

465

answers:

1

Hi, I am facing sync related issue in multi threading. I have an shared library which applications use to build there applications. From the library I have created a thread which listen to the request coming and process it its is real time thread.From the library i have invoked an API which is sync in nature which will wait for response to come from other module. This API has some dependency from other module from which response should come after the 1st response.But sometimes 2nd response comes 1st so the API get failed and sometimes it works fine. mutex locks arpit already applied. Can anyone tell me what should be the approach to fix the issue ?? I hope my question is clear.

EDIT: its on c + unix

+1  A: 

It would help to enhance your question with a time-sequence diagram.

Anyway, following your description the problem may be in: - some library is not designed for multithreaded use - not all operations are blocked by mutex (a good explanation of mutex can be found here) - thread/process priorities - mixed sync/async API's (i.e. one parameter is returned by an event whilst another is set using a function call)

If your only problem is the ordering, you may also try to enhance your API, for instance using a sequence number or timestamp. This way your code can find the earliest event.

I hope this helps.

Adriaan