LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-29-2005, 08:10 AM   #1
chanwing
Member
 
Registered: Feb 2005
Posts: 42

Rep: Reputation: 15
Qthread VS Pthread (threading problem)





Can anyone tell me what is the different of pthread and qthread? Are they do the same task?
Can I use pthread to replace qthread? or qthread to replace pthread?
What is GUI-thread and Non-GUI thread? Can I use GUI-thread for non-GUI? or can I use non-GUI for GUI?

I am now doing a school project.
I have to replace the MFC multi-threading by linux threading. (one part of my project)
However, I don't know how can I do.
In MFC, there are CEvent, CMutex, CCriticalSection and CSemaphore to access CSyncObject (win32). (all four objects method include in my project program)
But,..............
In Qt, there are QMutex, QSemaphore, QThread and QWaitCondition without any CSyncObject
In POSIX, there are pthread,semaphore,pipe,shared memory.
Can anyone tell me that can I use POSIX method in the Qt program?
Can I use pthread including the QThread?
Can both Qt and POSIX replace the MFC?
Which one is better to replace the MFC thread?

I really don't have any idea about thread.
Someone tell me that I can use the fork() and the shmget() to handle my task.
Can anyone help me and give me some advices??
Thank you very much
 
Old 06-29-2005, 09:10 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
If you are writing a program intended to be cross platform with the QT toolkit then QThread is what you want to be using.

Windows and *nix use different threading modules, QThread abstracts it out so when you compile the code for Windows it'll use the MFC threading model and when you compile the code for Linux it'll use the pthread model.

The QT Toolkit's whole purpose is abstract out the interface to the system when it comes to file i/o, ipc, networking, display, ect. so that you don't have to target your application to a particular OS.
 
Old 07-01-2005, 12:11 AM   #3
chanwing
Member
 
Registered: Feb 2005
Posts: 42

Original Poster
Rep: Reputation: 15
Oh, I see.

jtshaw, thank you very much

That mean I can use Qthread to handle MFC thread and pthread.

If I use both qthread and pthread, then will I get wrong or error?
 
Old 07-01-2005, 02:37 AM   #4
64bitprocessor
LQ Newbie
 
Registered: Jul 2005
Location: Bangalore
Distribution: Debian
Posts: 15

Rep: Reputation: 0
HI,
QThread is a part of the Qt Library. It can be used only with C++. It is very similar to the threads in JAVA. Qthread programs written using Qt can be recompiled and used in Windows.
Pthread means POSIX threads and it come with all *nix. It is a library for C.

regards,
64Bit

Last edited by 64bitprocessor; 07-01-2005 at 06:58 AM.
 
Old 07-01-2005, 06:40 AM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
You really want to stick with one threading model throughout your program. I imagine it could get very messy if you tried to mix the two.

QThread is probably your best option if you want it to work with Linux and Windows. pthread *might* be supported by the POSIX layer of windows... but I can't confirm or deny that statement.

As for what 64bit said above... pthreads is in fact the POSIX thread library and it is in fact implemented in C (though you can use it just fine from a C++ program). However, it is certainly not exclusively 64-bit architectures...
 
Old 07-01-2005, 07:05 AM   #6
64bitprocessor
LQ Newbie
 
Registered: Jul 2005
Location: Bangalore
Distribution: Debian
Posts: 15

Rep: Reputation: 0
Hi,
It true, you should stick on a particular thread model. We can use the pthreads in C++, even with the Qt libraries. But it will affect the portability of your code. Pthread is much efficient than the Qthread and in Linux Qthread is implemented by using pthread. pthread can be used with both 32 bit and 64 bit aplications.
 
  


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
Possible pthread permission problem Zotty Programming 1 06-05-2005 02:50 PM
pthread problem on redhat9 wizardjack Programming 4 02-02-2005 08:54 AM
pthread signal problem again xinwang00 Programming 4 11-18-2003 02:21 PM
pthread problem robnob Programming 16 11-12-2003 07:49 PM
pthread signal problem xinwang00 Programming 12 11-11-2003 02:30 PM

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

All times are GMT -5. The time now is 02:59 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