fix theadpool shutdown
only the first pool is stopped before being all pools are destroyed.
Comments (5)
-
-
Account Deactivated Very interesting! Thanks for spotting this. I understand that it is incorrect to clean-up the underlying memory location without shutting down the corresponding pool but I don't quite understand how a thread that has no memory location associated with it continues to execute in the system and can get re-linked to another task! Can you please help me understand this?
Pradeep.
-
void Encoder::stopJobs() is called fromvoid x265_encoder_close(x265_encoder *enc)which only stops the first set of jobs in the m_threadPool array. Subsequently, encoder->destroy()uses delete [] m_threadPool; which deallocates theunderlying memory of the entire threadpool, even the onesthat are still running, waiting on a lock to start work.
-
I probably should add that the threadpool is still referenced by the dormant tasks and the memory it is watching can be reallocated to any other running task that demands memory. On my system, this is what is happening. the lock locations which stop execution are now used from elsewhere. If the new owner modifies memory in a way that triggers a dormant lock, the latent owner resumes and is surprised to find the underlying memory is updated.
-
- changed status to resolved
Thanks for the pointer - ee38630033b7
- Log in to comment
This problem is worse than it looks. During encode, it creates a bunch of tasks in several pools, runs, and only shuts down the first pool. Then, it deletes the underlying memory allocation for all of the tasks, which then may be reallocated. If the program only has one pool, or terminates immediately, the bug is moot. If not, sooner or later a lock location is twiddled, and one of the dormant task resumes and explodes.