LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2004, 01:23 PM   #1
penny21
LQ Newbie
 
Registered: Mar 2004
Posts: 17

Rep: Reputation: 0
Unhappy threading using kde


hi

I am trying to write some program in linux using kde and QT. I am going to add some threading functions into the program but is having problem with it. What lib should i use for the threads? Saw that glib has some threading functions to use but my kde does not recognise the glib. How do i get the kde to link to glib?

BTW this is a super newbie who needs to hand in the program in a week time!!!

Please help
penny
 
Old 03-03-2004, 09:07 PM   #2
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
Search online for POSIX threads

They're the main thing in *nix threading
 
Old 03-04-2004, 08:12 AM   #3
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
/*
Don't forget this; you may have to specify full path or pass directory to
gcc via -I option
*/
#include <pthread.h>




/*
Our thread function
*/
void* my_thread_func(void*){
//Whatever it does
.
.
pthread_exit(NULL);//Or some void* if required
}



/*
Thread function(s) is/are created here
*/
void my_thread_creation_func(void* data){
.
.
pthread_t thrd_handle;
int tcr_res;
//Start the thread;you may pass pthread_attr instead of NULL
tcr_res=pthread_create(&thrd_handle,NULL,my_thread_func,(void*)data);
.
.
}

BTW if the thread function is a class method, don't forget that it must
be static.

HTH
 
Old 03-04-2004, 10:23 AM   #4
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Use the thread class in Qt (more portable than POSIX threads)

Alex
 
Old 03-06-2004, 01:04 PM   #5
penny21
LQ Newbie
 
Registered: Mar 2004
Posts: 17

Original Poster
Rep: Reputation: 0
thanks for all the replies ... i have used the Qthread class to implement my threads. but after i write my own cpp file which inherit the qthread and write the run(), i have compile error which says "multiple definition of run() and ClientThread". Anyone has any idea what happen and how to solve it?


sample of my code is below

class MyThread : public QThread {

public:

virtual void run();

private:
void ClientThread(SocketServer );

};

void MyThread::run()
{


SocketServer server ( 2113 );

SocketServer client;

while(true)
{

client.accept(server);
ClientThread(client);
}

return;
}



void MyThread::ClientThread(SocketServer client)
{

while(true)
{
//handleClientRequest

}

closesocket(client);
return;
}
 
Old 03-08-2004, 01:43 AM   #6
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
1. Put the class and all other declarations in a separate .h file (which the
.cpp should #include

2. Start the header with
#ifndef _C_Nameofmyheader_h_
#define _C_Nameofmyheader_h_

and end it with

#endif


HTH
 
Old 03-09-2004, 04:25 AM   #7
penny21
LQ Newbie
 
Registered: Mar 2004
Posts: 17

Original Poster
Rep: Reputation: 0
thanks very much maruis2!
it works

YIPPPEEEEEEEEEEEEEEEEEEEEEE
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gettid() and threading... mrshadow76 Programming 1 10-17-2005 12:02 PM
Threading JanusPaul Programming 2 02-09-2005 03:39 PM
mutt threading sanjiv Linux - Software 0 07-25-2004 05:00 PM
Hyper Threading enragedchip Linux - Hardware 1 02-12-2004 06:05 AM
Multi threading Mohsen Programming 5 03-01-2003 11:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration