Results 1 to 2 of 2
Dear forum hello,
I'm currently writing a User-Level Thread Library.
The general idea is very simple:
I have a struct called Thread.
Each Thread contains relevant member fields as well ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-14-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 5
User Threads - Memory Protection
Dear forum hello,
I'm currently writing a User-Level Thread Library.
The general idea is very simple:
I have a struct called Thread.
Each Thread contains relevant member fields as well as a stack at the end.
From the so-called Main Thread I malloc new Threads on the heap.
Now I want to protect these threads' memory.
Had I been using the kernel to create threads, I'd be getting SEG_FAULTS and all would've been good (well considering that you have a bug - you know about it, when it happens).
But I'm not!
How can I protect each thread's memory? How can I prevent its data being over-run by another thread in the same application?
10x in advanced,
David
- 04-16-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,232
Since you are writing your own threading library instead of using the posix pthread library, you might want to look at the pthread_mutex... system library calls to get an idea how to implement a mutex lock. A mutex (mutually exclusive) lock will serialize access to critical resources such as you need to do. This can also be implemented with standard semaphores, and in some cases mutex locks do just that.
So, this is a class project?Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
