Thread: thread and shared memory manipulation

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    thread and shared memory manipulation

    i m working with posix threads and two of my threads are simultaneously accessing a global variable...may i know of a way to suspend action of one thread only for that variable unless the other has performed opereation....can u give me a code snippet for the same...please note i dont want to mutex lock the thread since it blocks the whole thread..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    7
    but then the thread neva answered as to how to solved my problem...coz m facing it....i mean if it could be syntax or probably a small example

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well you use a semaphore or a mutex to guard the access to the variable.
    http://www.llnl.gov/computing/tutorials/pthreads/
    http://yolinux.com/TUTORIALS/LinuxTu...ixThreads.html
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    7
    thanks a lot....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BSD mmap for shared memory - am I right?
    By sean in forum Linux Programming
    Replies: 21
    Last Post: 03-09-2009, 01:57 PM
  2. Problem with linked list and shared memory
    By Sirfabius in forum C Programming
    Replies: 10
    Last Post: 11-10-2008, 04:45 PM
  3. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  4. Shared memory implementation using thread
    By kumars in forum C Programming
    Replies: 5
    Last Post: 06-18-2008, 04:24 AM
  5. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 05:34 AM