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

Issue about ucos2_pthread #74

Closed
KevinShuuichi opened this issue Jul 8, 2021 · 1 comment
Closed

Issue about ucos2_pthread #74

KevinShuuichi opened this issue Jul 8, 2021 · 1 comment

Comments

@KevinShuuichi
Copy link

Hi, Mr.Vincent:
I used ucos2_pthread to perform some multi-thread tasks. The miniGui version is 3.2.2. I created a thread using pthread_create(&threadID, 0, subThreadCallBack, NULL), and I put a pthread_exit(0) at the last of subThreadCallBack. In the main thread, I used pthread_join to wait the subThread to be finished. I found the pthread_join is useless. So, I debuged the code in ucos2_pthread.c. There're something strange.

  1. In the function of pthread_info_id: we don't need to calculate the index, the id is exactly the offset of thread_table, because the thread id you created in pthread_create is set to nthread - thread_table.

  2. In the function of pthread_join: if the pthread_join( ) is performed first, it locks the pthread_mutex, then if the state is running , it will go to OSSemPend(joinee->joiner, 0, &ucos2_err) to wait subThread to exit. But in the pthread_exit(), it locks the pthread_mutex again, it's a dead lock. These two thread is running forerver. So I think it should unlock before pthread_join goes to OSSemPend.

  3. In the function of pthread_exit: OSSemPost(self->joiner) only happens when nr_joined is greater than 0, but before the OSSemPend in pthread_join, there is no code to add 1 to nr_joined, so it can't post the sem. pthread_join is locked forever.
    These are some issues I have found by now. Or maybe it's just my misuse. Looking forward to your reply.

@VincentWei
Copy link
Owner

I think your analysis is correct. There are some bugs in the implementation.

However, we have no dev. environment to fix or test the change. I think you can try to fix them and send us a PR.

Thanks in advance.

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