Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Lightbulb 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,

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts