pthread-memcpy-free problem

hi all,

I am doing video & Audio decoing by capturing MPEG2TransportStreams

To Decode Video I am using avcodec library (static)
To Decode Audio I am using Mp3(Mp3lib) & AAC(faad) librarys (Shared)
(FYI :All libraries are reentrant)

Let me say there is 100 channels from MP2Tansport stream.I need to create 100 Audio & 100 video Threads.Here i am able to run for 10 Threads.

But for more than 10(Audio & video) threads,Resource(CPU usage & Memory usage) are not enough to decode.For this problem I have decided to create threads by Round-Robin concept.

Creating-running 1st 10 threads for some minutes(say for 1 minute).After 1 minute kill 1st 10 threads , start next 10 thread. this Round-robin will continues...

This Round-Robin concept is working fine (1st -10thread ,2nd -10thread ... 10th -10thread ,again 1st 10 ... keep going)


Here the problem is , after 3 , 4 rounds problem while "memory copy","arithmetic operation","memory allocation".

To be detail main thread spawning child threads(no 10) with some time period . After some time period main thread tries to kill the child thread. While killing the child thread we are deleting the child thread pointers. In the mean time child thread tries to do some operation like "memory copy","arithmetic operation","memory allocation".At this time Program exits.(B'caz no pointers to copy ,to do some operation).
after 2 or 3 or 4 rounds application exits.I couldn't say when the application is going to exit.


FYI :
Creating thread by using pthread_create.
Cancelling the Thread by using pthread_cancel.

I have tried Thread_mutex operation, Horad (Library for multithreading memory operation), TBB (Intels Thraeding Building Block) too

Requirement is to run application continuously

Thanks in advance

Regards
Jaishree
Have the thread functions' main loops test a boolean to determine whether to continue. When the boolean goes false, exit the loop, clean up, then call pthread_exit(0).

The main thread will set the boolean to true before starting the 10 threads and set it to false to kill them.
Hi Hammurabi,

thank you for your response

obviously, main thread is having boolean to determine whethear to continue.

FYI : Cancelling the Thread by using pthread_cancel. not using by pthread_exit(0).

while(pthread_cancel(Thread_ID)!=0)
sleep(1);

If use pthread_exit(0) , main thread exits.

Application exits in child threads while doing memcpy,malloc or arithemetic operation (inside the libraries tooo)

My doubt is that:

I am using MultiProcessor .

Let me say in 10 threads , 1st thread tries to do operation "free" some memory. so it frees some memory.Here the free happens for some whole block as per "Paging" concept . That freed block may contain 2nd threads memory allocated pointers.

When 2nd thread wants to do some memcpy or malloc or arithmetic operation or free memory pointer ,at this point problem arise

If suppose this is the problem what could be the solution for it?

Thanks in advance

Regards
Jaishree

Topic archived. No new replies allowed.