473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

MFC & multithreading application

darlene
Hi,

I need some help in creating an application in Visual C++ which should make use of MFC and multithreading. The application is supposed to consist in a number of threads representing factories. Each factory, implemented as a thread, can create only one type of the objects below: wheels, windows, doors, chassis or engines. From the GUI an user should be able to add a new factory or delete an existing one by specifying its type (eg. engine factory, or door factory). For each factory it should also be possible to be printed how many products it has made since it was created. The time required for creating an object is defined by the user from the GUI for each factory.

I do not know much about multithreading except what i've read in some tutorials over the internet. i know i must create a class hierarchy for these threads but i don't know exactly how to do it and i need some idea where to start from. any kind of help is more than welcomed,

thanks
Jul 30 '07 #1
7 4468
weaknessforcats
9,208 Expert Mod 8TB
There is far more to this than I can go into here.

The short lesson is:
1) you use the Win32 CreateThread() to create your thread
2) the thread function must be a ThreadProc
3) the thread function must be a static member of your class
4) you use events to communicate with your threads. Check out CreateEvent() and SetEvent()
5) the thread calls WaitForSingleObject on it's event handle to see if it should continue or abort
6) the main() calls WaitForMultipleObjects before destroying the event handles

Check out Programming Windows by Charles Petzold.
Jul 30 '07 #2
Banfa
9,065 Expert Mod 8TB
1) you use the Win32 CreateThread() to create your thread
In an MFC application you would be better off calling AfxBeginThread to create a new thread.
Jul 30 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
I'm not an MFC guy so you may be right.

I am suspicious of anything resembling beginthread since that function at Microsoft uses the CRT heap and is used when you want to look C-like by using errno, etc, which isn't Window-ese.

The Win32 call is CreateThread(). It's the only call so AfxBeginThread would havbe to call it at some point.
Jul 30 '07 #4
Banfa
9,065 Expert Mod 8TB
The Win32 call is CreateThread(). It's the only call so AfxBeginThread would havbe to call it at some point.
This is true, but AfxBeginThread adds the extra bloat around CreateThread that the thread requires to work properly with the MFC and is essential if you are creating a thread that handles part of the GUI. I have a feeling it isn't quite so essential if you are creating a worker thread (one that has nothing to do with the gui) that wont use any MFC classes.
Jul 30 '07 #5
Thanks for the hints, i've made more research on Google about this. As Banfa said I must use the AfxBeginThread to create my thread and others of its kind. I haven't managed yet to figure out though how to start this. I mean, I have to create a base class called factory which should be wrapped upon an UI thread I guess. This UI thread should communicate with my GUI and handle the user's input. From this class then I'll derive the WheelsFactory, EngineFactory, DoorsFactory and WindowsFactory classes which should also encapsulate a worker thread each. Those worker threads I will use to create my products (wheels, doors etc).

Is this correct? I don't know why i have the feeling i'm missing something ...
Jul 31 '07 #6
Banfa
9,065 Expert Mod 8TB
You sound like you are going to be creating 2 threads for each factory (1 gui, 1 worker) which sounds like 1 too many to me. Be sure you know exactly what each thread you plan to create will do. Be sure you know how each thread you plan to create will communicate with the other threads that it needs to.
Jul 31 '07 #7
nawito
2
I aready faced similier case over Windows XP.
Remember the max child processes is 64 you need to pass HANDLE as an static array not a pointer to an array.
Feb 14 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Michael | last post by:
Don't shoot me down guys, I know the Standard says nothing of threads and all.... As i understand it the STL does not support multithreading, however I want to use the STL in a multithreaded...
47
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
6
by: a | last post by:
Hello, I am doing some multithreading in an MDI app, and I can't seem to get the cursor to stay as an Hourglass. I call: Cursor.Current = cursors.wait at the beginning of my routing, and...
6
by: John Wells | last post by:
Guys, My boss has been keeping himself busy reading MySQL marketing pubs, and came at me with a few questions this morning regarding PostgreSQL features (we're currently moving to PostgreSQL). ...
55
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to...
19
by: jupiter | last post by:
Hi guys!!! Just one quick question... Which database module should I use when I want to use multi threading as my application requires lots of data from internet ???? I also want this database...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.