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

Error when calling pthread_cond_signal() function #8

Closed
edbek opened this issue Dec 20, 2016 · 5 comments
Closed

Error when calling pthread_cond_signal() function #8

edbek opened this issue Dec 20, 2016 · 5 comments

Comments

@edbek
Copy link

edbek commented Dec 20, 2016

Inside pthread_cond_signal() is called each time mtx_init().
mtx_init() is created the semaphore in any case:

mutex->sem = xSemaphoreCreateBinary ();

This condition should be avoided:

if ( !mutex-> sem ) mutex->sem = xSemaphoreCreateBinary ();

In addition, all of the objects by malloc () must be reset. Used calloc () or memcpy(0) after malloc().

@jolivepetrus
Copy link
Contributor

In pthread programming first you have to initialise the variables in the pthread style, using the initializer for that variable. For conditions, you must do:

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

Once variable is initialise you can use it in pthread functions. If you do this somewhere in your code prior to call pthread_cond_signal the mutext will be created once.

@edbek
Copy link
Author

edbek commented Dec 20, 2016

Ok.

But then you have to alter pthread_cond_init() function.
There is a situation when cond->mutex.sem ! = NULL, and then pthread_cond_init() function does nothing, and it should release the semaphore.
For example, the function introduction (where inside there pthread_cond_init)

pthread_cond_wait()
pthread_cond_timedwait()
pthread_cond_signal()

can not release the semaphore !

@jolivepetrus
Copy link
Contributor

Let me to make a review ....

jolivepetrus added a commit that referenced this issue Dec 21, 2016
* pthread_cond_xxx function revised (see #8)
* add unit test framework
* add test case for pthread_cond_xxx
* phtread library minor bugs
@jolivepetrus
Copy link
Contributor

Please, take a look at:

22d4b1d

@jolivepetrus
Copy link
Contributor

Let me to close this issue. No feedback were provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants