having problems with PThreads, not compiling!,, PLEASE PLEASE HELP

The following function seems to be the cause of the problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

template <class Type>
void * server_work(void * arg)
{
    int ii;
    int cno;
    Server<Type> * server = (Server<Type> *) arg;
    Customer<Type> newcust;

    for(ii=0; ii<QUEUE_LENGTH; ii++)
    {
        size_t length = rand()%(MAX_RANGE-MIN_RANGE)+MIN_RANGE ; // Generate the number, assign to variable.
        pthread_mutex_lock(&MUTEX);
        cno=CUSTOMER_COUNT;
        CUSTOMER_COUNT++;
        pthread_mutex_unlock(&MUTEX);

        newcust=Customer<Type>(cno, cno,cno,length);

        if(CUSTOMER_COUNT<=QUEUE_LENGTH)
        {
            server->IncreaseNumOfCustomers();

            for(size_t i = 0; i < length; ++i)
            {
                newcust.getLinkedList().insertFirst(1000);
            }
            server->getCustomers()[ii]=newcust;
        }
        else
        {
            break;
        }
    }

    return NULL;
}


Probelm occurs when the compiler reads the following bit of 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
int main(int argc, char** argv)
{


    pthread_t threads[NUMBER_OF_SERVERS];
    int i,j;


    if(pthread_mutex_init(&MUTEX, NULL))
    {
        cout<<"Unable to initialize a MUTEX"<<endl;
        return -1;
    }

    Server<int> servs[NUMBER_OF_SERVERS];

    for(i = 0; i < NUMBER_OF_SERVERS; i++)
    {
        servs[i].setServerNum(i);
        pthread_create(threads+i, NULL, server_work, (void *)&servs[i]);//<<--compiler flags here
    }

    // Synchronization point
    for(i = 0; i < NUMBER_OF_SERVERS; i++)
    {
        pthread_join(*(threads+i), NULL);
    }

    cout<<"SERVER-NO\tCUSTOMER-NO\tARRIVAL-TIME\tWAITING-TIME\tTRANSACTION-TIME"<<endl;
    for(i = 0; i < NUMBER_OF_SERVERS; i++)
    {
        for(j=0; j<servs[i].getCustomersServed(); j++)
        {
            cout<<i<<"\t\t"<<servs[i].getCustomers()[j].getCustomerNumber()<<"\t\t"<<servs[i].getCustomers()[j].getArrivalTime()<<"\t\t"<<servs[i].getCustomers()[j].getWaitingTime()<<"\t\t"<<servs[i].getCustomers()[j].getTransactionTime()<<endl;

        }

    }
    cout<<endl;
    cout<<endl;


i get the folloiwng error from the compiler:

main.cpp:84:71: error: no matches converting function ‘server_work’ to type ‘void* (*)(void*)’
main.cpp:26:8: error: candidate is: template<class Type> void* server_work(void*)

--
Thank U
Last edited on
Is the code below that what you intended?

1
2
3
4
5
6
7
template <class Type>
nodeTypeCount<Type> MisspelledList()
{
    list<string> _MisspelledList;
    list<string>::iterator it_miss;
    return _MisspelledList;
}


Then you return a list<string> even though the function is meant to return a nodeTypeCount<Type>.

Honestly I'm confused.
It flags an error on line 20 when i run it! :( now, i have corrected the above error now, i now have this one to deal with!
Last edited on
Topic archived. No new replies allowed.