Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lwip: fix lwip thread_create() wrapper #9588

Merged
merged 1 commit into from
Jul 26, 2018

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Jul 17, 2018

Contribution description

This is something @jcarrano noticed when testing out #9573. Casting a function without return value to a function with return value is obviously wrong, so we need a proper wrapper. The function in question is used by lwIP to abstract the system layer, so it is vital to lwIP running properly (this is why I set the major label as I think this should get two ACKs).

Issues/PRs references

None

@miri64 miri64 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking Impact: major The PR changes a significant part of the code base. It should be reviewed carefully Area: pkg Area: External package ports labels Jul 17, 2018
@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 17, 2018
void *arg = params->arg;
mutex_unlock(&params->sync);
thread(arg);
/* TODO: free stack? */
Copy link
Member Author

Choose a reason for hiding this comment

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

@kaspar030 any idea how we might do that? It's allocated here

Copy link
Contributor

Choose a reason for hiding this comment

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

If we were sure that the thread is not going to be forcefully cancelled, it could be done in the wrapper, before returning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Depending on the architecture, the stack might still be used to write the return value, so this sounds like a bad idea ;-).

Copy link
Contributor

Choose a reason for hiding this comment

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

@miri64 You are right. I just realized how stupid my comment was!! How can one going to release the stack if the function is still executing!

What we need is either:

  • A termination/cancellation function
  • A thread creation mechanism that handles stack allocations automatically.

Multithread programming sucks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, at the moment non of the threads started by lwIP terminate, so this is a more theoretical issue in case lwIP ever decides to have something that actually finishes ;-).

Copy link
Contributor

@jcarrano jcarrano left a comment

Choose a reason for hiding this comment

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

It's OK, except for the mutex usage. The release of the stack memory is a subject for another issue/pr.

abort();
}
mutex_lock(&params.sync);
Copy link
Contributor

Choose a reason for hiding this comment

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

This usage of mutexes - unlocking in a different thread than the one it is locked from- is kind of non-standard. I happens to work with RIOT mutexes, but I don't think it's a behaviour that should be relied upon or guaranteed.
The "correct" primitive for this usage is either a semaphore or a condition variable (I think we don't have those in RIOT).

@kaspar030 What do you think about this use of semaphores?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jcarrano since mutexes are the only reliable core synchronization mechanism RIOT has (at the moment) I rather go for them. If it works in RIOT, why not use it in RIOT ;-) (as it is in several other places, e.g. asymcute).

PS: there is a bug in sema that actually causes problems in lwip already ;-) #7035

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened a question-bug: #9594 .

Copy link
Contributor

@jcarrano jcarrano left a comment

Choose a reason for hiding this comment

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

All issues are addressed. There is still some open questions regarding thread creation and cancellation (see reviews).

@jcarrano jcarrano merged commit d3c75aa into RIOT-OS:master Jul 26, 2018
@miri64 miri64 deleted the pkg/fix/lwip-thread-wrapper branch July 27, 2018 06:35
@cladmi cladmi added this to the Release 2018.10 milestone Aug 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: major The PR changes a significant part of the code base. It should be reviewed carefully Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants