qns on multithreading and locking

say I have this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int startServer( struct ServerParameter &serverParameter )
{
    pthread_t threadID;
    ConnectionParameter *connectionParameter;
    SharedData sharedData;
    pthread_mutex_t sharedDataLock;
    int newFD;

    // initialize lock here

    while ( 1 )
    {
        connectionParameter = new ConnectionParameter();
        connectionParameter -> newFD = accept( serverFD, NULL, NULL );

        pthread_mutex_lock( &sharedDataLock );
        connectionParameter -> sharedDataPtr = &sharedData;
        pthread_mutex_unlock( &sharedDataLock ); 
        connectionParameter -> sharedDataLockPtr = &sharedDataLock; // Do I have to have a lock to this lock too?

        pthread_create( &threadID, NULL, &handleConnection, connectionParameter );
    }
    ...
}


In this line,
connectionParameter.sharedDataLockPtr = &sharedDataLock;

Do I have to have a lock to this lock too?
Last edited on
bump, help me pls
Those are your classes used in your program. How is anyone to guess what's shared from what you've posted?
err no my question is do I need a lock to sharedDataLock as well which is of type pthread_mutex_t?
Topic archived. No new replies allowed.