Hi. It looks like this: there is a worker thread, which just runs and there is a button, which when clicked, should send some data to this worker thread. And now i am thinking, how this can be done. First off, i am a little bit skeptical about pipes and global variables. More real-life example would be something like this:
1. There is a thread.
2. There is a dialog window which accepts files. When file is dropped on this dialog window, thread should be notified that new file has been dropped and receive an open handle to this file and a file name.
I was thinking about user mode APC but actually dont know if using this i can communicate with a thread or change its context, influence its variables, access its variables, modify them and use them - that would be great but the only thing i did so far with APC is terminating a thread.
Another scenario i can thinks of, is having some global structure, update it time to time, signal thread so it will know that our struct has been filled with some new info so the thread can grab it - but yet again, global variables - not so good.
Is there some "clear" and nice way of doing this?
Short answer: You'll use WaitForSingleObject[^] to wait on an event, critical section, or so (depending on your scenario). The event should be triggered (SetEvent[^]) when a file is dropped that needs processing.
Is there some "clear" and nice way of doing this?
If you're using MFC, you could use an UI thread[^] (the name is weird - an UI thread need not necessarily be associated with an UI). If you do it, you'll just post a message to the message pump of the thread and the thread will pick it off its queue and process it. This is an easy way, but it is an overkill if the thread is just supposed to do only one type of job (as opposed to doing different things based on the message posted to its queue).
You don't really need to "pass data to a thread", as all threads in a process have access to the same data.
I typically use a semaphore to signal the worker thread when there's a job to do. The "jobs" are queued in a collection of some sort, and whenever a job is queued, the semaphore's count is incremented, setting its state to signaled. The worker thread waits on the semaphore and pops a job off the queue (don't forget to synchronize access to the collection with a critical section!) and processes it any time the semaphore is signaled.
That's for a single worker thread...If I need a pool of worker threads, I'll use an I/O completion port instead....it does all the above and saves writing alot of thread plumbing code.
Hey Mark. I have never actually dealt with semaphores before, mainly events in a regular fashion as well as mutexes and now IOCP
Currently just needed some quick and dirty solution for this test project of mine, because it will land in a recycle bin as soon as i'll figure a couple of things out - just needed to smuggle pair of pointers here and there though Anyways, thanks for a hints - will probably need that in near future.
I got a project which is written in VC++ but while compiling its giving me following error in MS-VC 6.0.
"Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
No configuration specified. Defaulting to MyProject - Win32 Debug.
NMAKE : fatal error U1073: don't know how to make '"e:\win32app\microsoft visual studio\vc98\include\basetsd.h"'
Error executing NMAKE."
Please let me know which version of MS-VC6.0 will support this. OR do this project have 3rd party libraries. How to supress this NMAKE errors and complie the code successfully.
Thanks for your reply. I was able to resolve this problem but now I am facing following error
".\Release\MyApp.exe : fatal error LNK1120: 2 unresolved externals
NMAKE : fatal error U1077: 'link.exe' : return code '0x460'
Error executing NMAKE.
Do I need to change NMAKE file for this?
I tried to identify what is the problem for giving this kind of error and I found that one of function declared object of dialog class as follows
Dlg_Details *pDet = NULL;
and then it creates instance
pDet = new Details_Dlg();
and here it is giving following err
"error LNK2001: unresolved external symbol "public: __thiscall Dlg_Details::Dlg_Details(class CWnd *)"
.\Release\myapp.exe : fatal error LNK1120: 1 unresolved externals"
when i commented out above line of code (creating instance using new) then appln compiles and link properly.
I tried to go to the detail and found that the constructor of above class is declare as
"Dlg_Details(CWnd* pParent = NULL)" in header file and its implementation as in .cpp file is as follows.
"CDlg_Card_Details::CDlg_Card_Details(CWnd* pParent /*=NULL*/)
: CDialog(Dlg_Details::IDD, pParent)
variables are initialized
and I tried to changing its declaration in header file as
but still the problem persist. Can you suggest where this code going wrong during linking.
If I were doing it, I'd try Google translate, unless you can find someone fluent in both Chinese and English. If you try an automatic translator, like Google, you will surely need to clean up the results so you don't get hilarious or embarrassing text in your resource strings!
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
Last Visit: 31-Dec-99 19:00 Last Update: 30-Nov-23 6:36