thread and shared memory manipulation

This is a discussion on thread and shared memory manipulation within the C Programming forums, part of the General Programming Boards category; i m working with posix threads and two of my threads are simultaneously accessing a global variable...may i know of ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Like this recent thread perhaps?
    global variables and thread safety
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 03: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, 04:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21