Skip to content

Added multithreaded lock test.#73

Open
korjaa wants to merge 3 commits into
masterfrom
mutex_test
Open

Added multithreaded lock test.#73
korjaa wants to merge 3 commits into
masterfrom
mutex_test

Conversation

@korjaa

@korjaa korjaa commented Jul 12, 2017

Copy link
Copy Markdown
Contributor

This should detect issues with uneven locking and releasing.

Test flow:

  1. Create 10 threads.
  2. Each thread calls mbed_tracef() with different delays 10 times.
  3. Join 10 threads.
  4. Repeat 10 times.

@korjaa korjaa requested a review from jupe July 12, 2017 10:49
@korjaa

korjaa commented Jul 12, 2017

Copy link
Copy Markdown
Contributor Author

Now fails on:

CHECK((mutex_wait_count - mutex_release_count) > 0) failed

@jupe

jupe commented Jul 12, 2017

Copy link
Copy Markdown
Contributor

@tommikas could you check this out

@korjaa

korjaa commented Jul 12, 2017

Copy link
Copy Markdown
Contributor Author

A bit worried that https://github.com/ARMmbed/mbed-trace/blob/master/test/Test.cpp#L31-L38 wait and releases are just counters and not real locks.

@korjaa korjaa requested a review from tommikas July 12, 2017 11:06
@korjaa

korjaa commented Jul 13, 2017

Copy link
Copy Markdown
Contributor Author

The missing mutexes is going to be an issue, if this test is taken to use some modifications need to be done for the test mutexes.

@tommikas

Copy link
Copy Markdown

Now fails on:

CHECK((mutex_wait_count - mutex_release_count) > 0) failed

Off the top of my head I'm guessing that there are interleaved calls from more than one thread. When the first one exits the trace call it rolls back all the "mutex calls" from both threads. This shouldn't happen with a real mutex.

The missing mutexes is going to be an issue, if this test is taken to use some modifications need to be done for the test mutexes.

Yeah, with multiple threads it needs a real mutex. Should be no problem just initializing one and adding the calls to the wait and release functions. The counters should still work.

The original test just ensured that for all the tested calls the library releases the mutex as many times as it locks it.

@tommikas

Copy link
Copy Markdown

@korjaa Even if the original problem has been resolved it wouldn't hurt to have this kind of test in. Would you mind adding the mutex to the wait and release functions?

@korjaa

korjaa commented Jul 31, 2017

Copy link
Copy Markdown
Contributor Author

"Off the top of my head I'm guessing..."
Yes, the test was flawed to begin with :) And the counters should work with the correct mutexes.

"...to have this kind of test in"
I think in the case of deadlock the test will just get stuck and not return FAIL. Which I guess then would need more restructuring. Feels complicated. :(

@tommikas

tommikas commented Jul 31, 2017

Copy link
Copy Markdown

A deadlock shouldn't be too hard to catch. Use a "ready to join" flag for each thread to know when to call pthread_join on them and catch a deadlock either by simple timeout or by polling the counters for a (lack of) change from main thread. A timeout could also catch a livelock, if that could somehow happen.

@korjaa

korjaa commented Jul 31, 2017

Copy link
Copy Markdown
Contributor Author

Awesome, you already seem to have an idea how to solve this ;)

@tommikas tommikas removed their assignment May 29, 2024

@jupe jupe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks amazing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants