3
function A(int a[])
{
SemLock()

  //Some Code....

SemUnlock()

}

Suppose some other thread has taken the same lock. Hence this function is blocked. Suppose this function is called by many other threads. All will be blocked. After Unlocking, will the data (parameter a[]) be lost or retained passed in as the parameter by different threads. How does this queuing of data takes place?

Sumit Trehan
  • 3,985
  • 3
  • 27
  • 42

1 Answers1

2

parameter a[] is thread specific (non-shareable) so each thread has their own copy of a[]. When a thread created a data-structure for thread is created. a[] is stored in thread's stack.

There is a queue of thread associated with each semaphore variable.

typedef struct {
int count;
queue q; /* queue of threads waiting on this semaphore */
} Semaphore; 

[ANSWER]
a[] will not loss.

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
  • This [LINK](http://www.mpi-sws.org/~druschel/courses/os/lectures/proc4.pdf) will be helpful to understand how semaphore works for thread. – Grijesh Chauhan Dec 17 '12 at 06:01