|
|
Thanks. I thought there had to be something, just couldn't spot it.
You the man!
cheers,
Neil
|
|
|
|
|
Anyone know how to place an HBITMAP into a PDF File? or Save a CDC as a PDF File?
Chris
|
|
|
|
|
|
|
I am using a CMSChart. When I want to save this thing as a file I have to copy the chart into the clipboard as a bitmap and then I can bring it out of the clipboard into an HBITMAP. From there I can save it as a bmp or a jpg. But then the user can easily go into paint and try to change the contents. If I could put the HBITMAP into a pdf then the average user will not be able to change or manipulate the picture.
Chris
|
|
|
|
|
Hi,
I am having an application written in vc++ in which it is having multiple threads (to say 2 threads) running parallel. These threads are created by the user at the same time, but ofcourse one after the other. I want them to be syncronized with each other so that they wont be off even by 33.3msec. Actuallly these two threads generate waveform signals through 2 waveform generator boards which finally generates images. So, the framerate will be at 30Hz. The problem is each thread generates two differnt images at the same frame rate, but while I replay the images they are "sometimes" off by one frame(33.3msec).
thanks,
-Pavan
|
|
|
|
|
Have you implemented any synchronization mechanism between the two threads, or just created them and let them go?
Best,
Jun
|
|
|
|
|
mswin does not provide us with much control of threads. They do not even give us a simple control to temporarily disable switching of threads. Just imagine if we could disable switching momentarily so that we could execute a couple of lines of code and guarantee that no other threads were run in between. It could prevent a mess of control flags.
Anyway, I always suggest... DO it in one thread! Then you do not have these problem!
Just livin a dream.. dont wake me!
|
|
|
|
|
mikeorama12345 wrote: Just imagine if we could disable switching momentarily so that we could execute a couple of lines of code and guarantee that no other threads were run in between.
Isn't this what a critical section does?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
All a critical section does is prevent another thread from running the protected section of code. He was asking about totally preventing other threads from running, which isn't possible.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
It is, but I think you have to be running Windows 3.1
|
|
|
|
|
Michael Dunn wrote: He was asking about totally preventing other threads from running,
I don't think so, but I'd like to hear what the originator says.
Michael Dunn wrote: which isn't possible.
Why not?
Best,
Jun
|
|
|
|
|
Jun Du wrote: I don't think so, but I'd like to hear what the originator says.
Isn't this the only way both threads can remain time synchronized? I mean the only way I can see this to work is he has to have a dual processor dual core machine with the two threds on their own cpu and that the operating system will never schedule any other threads (or yield execution) on either of the cpus that are runing the two threads.
|
|
|
|
|
My reply "I don't think so" is to Michael's comment that the originator wanted to prevent other threads from running. I think what the originator wanted (or needed) is sychronizing the tweo threads so that they output the same frame at a given time.
I see two issues mixed with the originator's question: real-time and synchronization. By real-time, I mean that the simulation time your program complete goes hand-in-hand with your wall clock, no faster no slower. Lets say you're simulating the traffic on a highway. You want your program to complete the simulation of one sencond traffic within one second time. Only this way you can acheive real-time. Multiple CPUs can help to acheive real-time through better parallelism. But if the computation is very simple, one CPU can do the job too. As you may notice now, parallelism is not a necessity in pursuing real-time.
Synchroniztion is a different issue. It is about the collaboration between two threads. It has nothing to do with how fast your CPU is. You don't need multiple CPUs to acheive synchronization. One of the major purposes for synchronization is protecting resources shared by more than one thread.
Best,
Jun
|
|
|
|
|
mikeorama12345 wrote: mswin does not provide us with much control of threads.
Compared to what, Linux?
|
|
|
|
|
That is what Mutex's, Semaphores/Critical Sections are for.
Almost forgot ... and events.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
-- modified at 15:31 Tuesday 27th June, 2006
|
|
|
|
|
mutex, boraphores, and critical sectionz are a bunch of clutter and a lot of work.
This is America. I dont want to work so hard.. I want to live!
I hope some day they invent simple macros:
LockThread ()
blah blah blah // YEY! I have 100% CPU unless timeout
UnLockThread ()
blah blah blah // ok go ahead and switch threads on me now, i dont care
Thread switching probably requires interrupts.
maybe we can use asm sti and cli ? (set interrupt and clr interrupt)
Just livin a dream.. dont wake me!
|
|
|
|
|
You mean something like this:
Main Thread
<br />
struct myData<br />
{<br />
shared_ptr<CCriticalSection> ptr;<br />
};<br />
<br />
void main()<br />
{<br />
shared_ptr<CCriticalSection> mySection(new CCriticalSection);<br />
myData data;<br />
data.ptr = mySection;<br />
HANDLE hThreads[2];<br />
hThreads[0] = CreateThread(..., &data);
hThreads[1] = CreateThread(..., &data);
<br />
while (WaitForMultipleObjects(...) == WAIT_TIMEOUT)<br />
{<br />
}<br />
}<br />
Threads 1 and 2
int Thread1(LPARAM pParam)<br />
{<br />
myData data = *(myData*)pParam;<br />
shared_ptr<CCriticalSection> mySection = data.ptr;<br />
<br />
while (IDoSomething())<br />
{<br />
mySection->Lock();<br />
mySection->Unlock();<br />
}<br />
return 0;<br />
}
Yes, sooo much more clutter ...
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
This was how it used to work with windows3.1 but a bad side affect of this is that with this policy any application could steal 100% of the cpu for as long as it wants and if it crashed during this time down went the os.
|
|
|
|
|
depends cpu count
waitt0
t0
++
signalglobal
waitt1
t1
++
signalglobal
waitglobal
if ()
signal t0,t1
Kuphryn
|
|
|
|
|
Windows is not a real-time OS, it does not give you control over when your threads will run. You can try increasing the threads' priority, but still, if some higher-priority task comes along, it will get CPU time and there's nothing you can do about it.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
Thanks for all your replies. Yep, I think my question should state as 'Parallel/simultaneous processing of multiple threads'. Synchronization is more related to resource sharing between threads. The problem is to run both threads exactly at same speed and at the same time (which assures the frame rate). I have tried several ways by defining the priority classes to both threads to HIGH_PRIORITY_CLASS and setting their priority to PRORITY_TIME_CRITICAL, but still 'sometimes' I am getting a difference of one frame between 2 threads. I am running my application on a Dell Precision 670 (Dual xeon processors) with 2 threads on each core.
Here is how my application works-
I am having 2 waveform generating boards on 2 of my 64-bit PCI slots. In my application I am generating waveforms on both of these boards and each thread generates waveforms on each of these boards. These boards will have on-board buffers where we can store the data to be generated as waveforms. Since these buffers are to be in multiples of 1024 and my data is not in multiples of 1024, as usual, I am using rotating buffers. The board buffers, data buffers are completely independent for both threads (each thread is having its own buffers), so no data is shared between these threads except the intial flag variable which initiates the starting loop in the thread. Neither of these threads change the flag. They just use it to start their wave form generating loop (just like as a trigger signal).
At last I would like to know how we can make sure these threads run at the same rate and speed and at any given instant of time they both should be at the same point of execution (one more thing is both these threads have exact and same number of instructions).
thanks,
-Pavan
|
|
|
|
|
hello
when I write :
mouse_event(MOUSEEVENTF_RIGHTUP
,mouse.x
,mouse.y
,0
,GetMessageExtraInfo());
it works , but with MOUSEEVENTF_LEFTUP notting happens.
do anyone knows anyway?
thanks
|
|
|
|
|
how to access com port in VC++
|
|
|
|