|
i never use such code, can you explain detail thanks a lot. how to use sprintf() function to do this? thanks
gentleguy
|
|
|
|
|
|
So what exactly do you need help with? What code do you have so far? What does your data structure look like?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi All,
I am beginer for Threading program.I did some programs on all the four thread synchronization classes(CCriticalSection,CMutex,CSemaphore, CEvent). Now my question is "What happens if a thread which locks a resource crashes/terminates without unlocking it?"
Thanks in Advance.
|
|
|
|
|
ss431 wrote: "What happens if a thread which locks a resource crashes/terminates without unlocking it?"
That resource will be locked for ever and no other threads can lock it again.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thank you for your reply Raj,
If the resource is locked what we have to do to unlock that locked resource and make it used by other Threads.
If the resource is locked by CMutex object then there is no problem as it will automatically unlocks the locked resource after the thread whick locks it is exited. But what about the situation if we use CCriticalSetion or CSemaphore,as they don't release the resources automatically.
|
|
|
|
|
ss431 wrote: Now my question is "What happens if a thread which locks a resource crashes/terminates without unlocking it?"
Well, it depends what kind of resource it is and what kind of synchronization object you've used to control the access to the resource.
If the resource resides only within your process, you should use a critical section (also known as a fast mutex) to synchronize access to the resource from different threads in the process. If the process crashes, you don't have a problem since the resource is gone as well.
A critical section is not a kernel object and is used to synchronize resources between threads in the same process.
If it's a global resource you cannot use a critical section to control access to it, you have to use a kernel object such as a mutex and give it a name (identity) in order for other processes to use the same mutex when accessing the same resource.
If a process that has locked the global resource with a mutex crashes, the mutex remains locked, preventing other processes from locking it and obviously preventing other processes from using the global resource. This scenario will likely freeze your computer.
Mutexes, semaphores and events are kernel objects and can be used for synchronization of access to global resources between processes.
Critical sections are not kernel objects and can only be used within a single process to synchronize access to process local resources such as queues shared between threads.
Reading tips:
To avoid common pitfalls when starting out with multithreaded programming, read this excellent article[^].
To know how to distinguish between when synchronization can or should be avoided and when it's absolutely necessary, read this article[^].
To know how to use synchronization objects, read this article[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
In addition to Roger's reply...
You should also do everything you can to make sure your threads can't crash...
Handle exceptions, use good error checking, etc
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi everyone,
I encounter a problem when combining 2 workproject together. I am currently using Microsoft Visual C++ 6. I need to combine the 2 workproject which are initially in 2 different workspaces because I have created the projects separately and want to combine them into 1 program.
Here is the scenario:
I open project A and then add project B to it. I set Project A as active project. I create a button in the main dialog box of Project A to open up the main dialog box of Project B but cannot seem to do so.
Apparently it seem to be that the new workspace folder only has the files (.rc, .h, .cpp) of Project A and I am able to see Project B in the workspace due to some linking mechanism (I guess)
May I know how to combine 2 projects and successfully link them?
Rgds
kindaichinisan
|
|
|
|
|
Two projects are still two different projects, even if they are in the same workspace. Grouping them into a workspace is just a matter of convenience: for example, you are developping a dll which is used by an exe. In that case, it makes sense to group them in the same workspace because once you modify the sources of the dll, then the exe will also be rebuilt.
But still, they are two different projects.
|
|
|
|
|
Okay, thanks for the prompt reply.
Is there a way to achieve what I wanted, as in combine 2 programs such that the dialog box of 1 program will open up the dialog box of the other program. They are in different workspace
|
|
|
|
|
Well, if you have to do something like that, it probably means you have a design issue. Why would you want to open a dialog box from a completely different project ?
|
|
|
|
|
I thought it will be a common problem. As in for large scale project, normally there are 2 or more ppl doing a project. Each person will be in charge of a certain part of the project. Later, they will combine their individual sub-project into one project.
|
|
|
|
|
kindaichinisan wrote: Later, they will combine their individual sub-project into one project.
You cannot "combine" several projects into one. Unless you are talking about code.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Hi gray man.
|
|
|
|
|
I'll see to it if I can make you a red man.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
kindaichinisan wrote: As in for large scale project, normally there are 2 or more ppl doing a project. Each person will be in charge of a certain part of the project. Later, they will combine their individual sub-project into one project.
That's not how it is done. Typically, everybody will have a 'copy' of the workspace and work on it. The full project is managed through a versioning system (like SVN) which allows each developper to submit his changes. The versioning system will then merge the changes with the previous version.
|
|
|
|
|
This is actually a lot simpler than these veterans are making it, Kindaichini-san
Create your first dialog, and the second, in separate (or the same) workspaces, and get them both running.
You'll notice that you have created a CSOMENAMEDlg class. Your "program" is in the CSOMENAMEApp.cpp file and consists of
include #CSomenameDlg.h
...
CSomenameDlg myDialog;
myDialog.doModal();
... "
All you have to do to combine the two is, create a copy of the "master" dialog, or create a new win32 app, as a master project, and then make sure you get all the files that your CSomenameDlg class needs to compile in that master project.
If you want to instantiate a CXXXDlg from a former, you need to make CXXXDlg member object, because when these go out of scope, they disappear.
You can either run them with .doModal() or with .Create(...), and I think if I keep typing, I'll reveal exactly how little I really know.. good luck!
-edit: /pre tag >.<
|
|
|
|
|
Hi bulg,
Your idea is to copy all the .h and .cpp file from my 2nd project folder to my first project folder. I managed to do that but for the 2 project folders, there is a resource.h file which keeps a list of ID names and numbers. There seem to be a unknown mechanism that ms visual c++ 6 use to keep track of ID (that I don't know else I may be able to proceed.) My question will be : how to merge 2 resource files together so that I would be able to call the dialog of Project 2 from a class of Project 1
Project 1
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
...
#define IDC_DOWN 1014
Project 2
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
...
#define IDC_UDTB_PULSEWIDTH 1005
#define IDC_UDTB_PULSEAMPLITUDE 1006
#define IDC_BN_START 1007
Thanks for all the help rendered by everyone.
|
|
|
|
|
This error msg occur when i am calling property sheet.
"
Debug Assertion Failed!
Program...
File:f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\dlgprop.cpp
Line:1184
For more information on how your program can cause an assertion failure,see the visual c++ documentation on asserts.
(Press Retry to debug the application)
"
I m using SDI type application in VC++ 2005, this problem is occured when i run my application in Debug mode.
If i run my application in Release mode then it is working properly, but i want to use in Debug mode .
So please tell me how can i remove this error.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Use your debugger to locate the problem properly. Press F5 to start, and once the crash occurs, use the callstack to locate the problem in your sources. You will be able to see a bit more in details what the problem might be (you'll also be able to inspect the different variables).
|
|
|
|
|
Its minimum info can you show line that products this error?
|
|
|
|
|
So have you looked at line 1184 of dlgprop.cpp ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi Gurus!
I am a relative newbie to VC++ and I am now working on a small VC++ prj wherein I need to convert what is currently an exported DLL into an exe.
An insight into what the DLL does:
It primarily exports User Interface functions for a parent app. The objective is to convert this DLL into a standalone exe application.
I'd be very thankful for any suggestions to get me going...
Thanks in advance,
Rennie.
|
|
|
|
|
The short answer is: you can't. But what you can do is start a new exe project from scratch and then reuse part of the code of your dll.
|
|
|
|