0

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

4
  • It may help to know which version of which Unix. That may determine which threading libraries are available. Commented Jul 31, 2009 at 12:37
  • 1
    Your question isn't clear. I am guessing that you have a situation in which A calls B and B replies with the answers in an order different from what A is expecting? How are the answers coming back from B? Are they coming over an inter-thread message queue, over a socket, by B calling callback functions? Commented Sep 3, 2009 at 23:21
  • Yap you are rite. B is getting some other answer which it is supposed to get back to A now A is expecting the ordering in the the answer.They are coming in thread. Commented Sep 5, 2009 at 12:21
  • Suse10 is Linux, not Unix. Is the kernel 2.4 or 2.6? Threading is not the same on these two versions. Commented Sep 17, 2009 at 14:07

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.