|
This book will quickly show you (by full example) how to create fully functional WPF applications using C#, XAML, and Visual Studio 2010 or 2012, SQL Server 2012, LINQ, Entity Framework, and the DataGrid
|
|
|
|
|
I have a worker thread running and would like to notify the main thread about changes in the worker thread. Call it synchronization if you prefer that.
I understand “wait for event” does not load CPU (much or nil ) , per documentation.
<b>But if this is a worker thread of low priority would plain while / do loop load on CPU be also OK? </b>
Since I know approximately how often ( in seconds) the event occurs I could use timer also.
The notification is asynchronous, not real time critical.
Any comments on that?
Cheers
Vaclav
|
|
|
|
|
Even though the thread might be low priority, it will still cause 100% cpu usage. I would recommend strongly against it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I think loop is the worst plan, it waste a lot of CPU cycle.
timer is OK
and sometime thread is a good solution
|
|
|
|
|
BTW, why do you want to wait on the worker thread? I simply don't understand this. Usually when a worker finishes with something you want to send an event to the "owner" of the worker thread immediately.
do-loop / "spinning" is almost always a bad advice. Spinning is usually acceptable only in the form of a spin lock in some special cases of locking where it can terribly outperform normal locks.
Thread priorities: Don't mess with thread priorities. Especially if your software is crossplatform. The best is to run everything on normal priority in most user space applications. In some cases setting the priority of some background data-loader threads to lower priority can help making the gui interaction smoother (usually if the machine is single-cpu and the IO terribly blocks on the background thread for some reason).
What does the main thread do? Is it prepared for the event? Your job would be pretty easy if the main thread would be a gui thread or some other kind of thread that processes jobs/tasks from a blocking message queue.
Timer??? Why do you need a timer and on which thread? Why don't you want to send the event from the worker thread immediately?
|
|
|
|
|
The main thread initialize worker thread whose job is to "send" timed audio to the main thread for processing (FFT). It is a test application, eventually it will be receiving real time data - audio - hence real time thread usage which will be time critical.
I just posted a similar question, maybe that will explain why I do this such convoluted way.
The key is how to monitor the WHDR_DONE flag which gets set AFTER the audio write is started / processed.
In other words - I am missing the "link" between waveOutWrite and WHDR_DONE.
<b>waveOUtWrite by itself does not wait for the WHDR_DONE flag to set. </b>
|
|
|
|
|
Well, I'm not familiar with that function call but it seems to me that the signaling of the completion of the data transfer is very primitive in this case and it seems that you will have to poll the flag. If its all about the right polling technique then... Depending on the architecture you may have to use at least an "acquire" memory barrier on the thread that polls the flag in order to notice the change in time. You start writing out a wave data chunk that is enough for the hardware for at least X milliseconds so your poll interval should probably be less than X/2 milliseconds to be successful but if the hardware has enough free buffer space then the transfer may complete in much shorter ("nearly zero"...) time then X milliseconds. If the precision of the OS scheduler is good enough then you can avoid busy-wait (do-loop) polling of the bit by sleeping for short periods between doing single-polls. If the OS scheduler isn't precise enough (for example because it can't put your thread to sleep state for shorter period then your Y poll period) then you have to do busy-waiting. Avoid busy waiting if possible, for example by writing out a large chunk that contains more than S*2 milliseconds of data if the period of the OS scheduler is S if possible. That way you can avoid busy waiting by polling this way: Sleep(S), check the flag, Sleep(S), check the flag,... This wont spin your poll thread. There are some situations when the only solution is spinning depending on the scenario but often it isn't.
|
|
|
|
|
Vaclav_Sal wrote: I have a worker thread running and would like to notify the main thread about changes in the worker thread. See the PostMessage() comments here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks.
It helps academically , I hope, but does not solve the stupid flag issue.
|
|
|
|
|
I'm in the mid of my project.
My task is to create an RTP server that can stream a file using ffmpeg in VC++. I got the ffmpeg.c but its complicate to understand for me. However I can:
Open the file using ffmpeg and can read it or can read the frames those are to be transmitted using VC++
But I'm not getting any way to stream it.
Please share your Experience and suggestions.
Thanks!
|
|
|
|
|
i've just doing a project like yours. i have refer to live555.com for my server and rtp directshow filter for my client
|
|
|
|
|
Thanks for giving time on this thread.
If you don't mind,will you please share some code snippet? so that I can understand better.
|
|
|
|
|
please help me to color the Subitem text of CListCtrl .
I m derived a Class from CListCtrl and write a code on its Custom draw but its not color the ListCtrl subitem text color
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
*pResult = CDRF_DODEFAULT;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{
COLORREF clrNewTextColor, clrNewBkColor;
int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
CString strTemp="";
if(pLVCD->iSubItem==8)
{
strTemp = GetItemText(nItem,pLVCD->iSubItem);
if(strTemp == "Y")
{
clrNewTextColor = RGB(0,0,255);
clrNewBkColor = RGB(255,255,255);
}
else
{
clrNewTextColor = RGB(0,0,0);
clrNewBkColor = RGB(255,255,255);
}
}
else
{
clrNewTextColor = RGB(0,0,0); clrNewBkColor = RGB(255,255,255); }
pLVCD->clrText = clrNewTextColor;
pLVCD->clrTextBk = clrNewBkColor;
*pResult = CDRF_DODEFAULT;
}
please help me correct me where I am wrong
|
|
|
|
|
Le@rner wrote: ...but its not color the ListCtrl subitem text color What color is it? What color do you want it to be?
What is the value of pLVCD->nmcd.dwDrawStage ? Of pLVCD->iSubItem ? Of strTemp ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
When changing colors, you must return CDRF_NEWFONT to notify the control that they has been changed (see last sentence at MSDN article Using Custom Draw[^]).
|
|
|
|
|
Hi All
When I draw button with style :
ModifyStyle(0, BS_OWNERDRAW);
but function DrawItem : no message ODS_DEFAULT.
I can't draw state default of button .
Example : Dialog have edit control and button.
With button no custom : Windows draw focus default button and focus edit control.
With button custom : I can't draw state focus of button when focus edit control .Need press TAB draw state focus of button.
Can you help me ?
Thank.
|
|
|
|
|
Some code segment in chapter 10 of "Windows via C/C++"(5th Edition) is
CEnsureCloseFile hFileSrc = CreateFile(pszFileSrc,
GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_NO_BUFFERING |
FILE_FLAG_OVERLAPPED, NULL);
Here "CEnsureCloseFile" is a class. The Author define Template class "CEnsureCleanup" which was used to clean some objects, then use a this Template define class CEnsureCloseFile
My question is why the HANDLE created by "CreateFile" can be assigned to object hFileSrc . It seems rare. Do you offen do sth like this?
|
|
|
|
|
Since it's just a pointer, it can be set to anything that can handle that appropriately (the constructor for this object likely takes in that type of HANDLE). His class probably just makes sure a file is properly closed without requiring you to explicitly close the file (open file handles can be an issue).
http://en.wikipedia.org/wiki/Assignment_operator_(C%2B%2B)[^]
|
|
|
|
|
|
digitalspace.xjtu wrote: why the HANDLE created by "CreateFile" can be assigned to object hFileSrc .
because the class has an overloaded '=' operator.
i don't have the source, but i imagine it looks like this:
TYPE operator=(TYPE t) {
Cleanup();
m_t = (UINT_PTR) t;
return(*this);
}
i do stuff like this all the time. i have dozen of little classes designed to take a handle of some kind in the constructor and then call the appropriate release/delete in the destructor.
|
|
|
|
|
Oh, it is operator overload , thank you very much
|
|
|
|
|
Hi to all,
I am able to generate DSA 512 bit KeyPair using crypto++ using the following code
<br />
<br />
bool CreateDSAKeys()<br />
{<br />
<br />
CryptoPP::AutoSeededX917RNG<CryptoPP::AES> prng;<br />
<br />
try<br />
{<br />
<br />
CryptoPP::GDSA<CryptoPP::SHA1>::GroupParameters pqg;<br />
pqg.GenerateRandom (prng, CryptoPP::MakeParameters(CryptoPP::Name::ModulusSize (), 512)(CryptoPP::Name::SubgroupOrderSize (), 160));<br />
<br />
OutputData(output, "P ", pqg.GetModulus (), pqg.GetModulus ().ByteCount ());<br />
OutputData(output, "Q ", pqg.GetSubgroupOrder(), pqg.GetSubgroupOrder ().ByteCount ());<br />
OutputData(output, "G ", pqg.GetSubgroupGenerator(), pqg.GetSubgroupGenerator ().ByteCount ());<br />
<br />
CryptoPP::GDSA<CryptoPP::SHA1>::Signer priv;<br />
priv.AccessKey().GenerateRandom(prng, pqg);
DSA::Verifier pub(priv);<br />
<br />
OutputData(output, "X ", priv.GetKey().GetPrivateExponent(), priv.GetKey().GetPrivateExponent().ByteCount ());<br />
OutputData(output, "Y ", pub.GetKey().GetPublicElement(), pub.GetKey().GetPublicElement().ByteCount ());<br />
}<br />
}<br />
But, The length of the PrivateKey x Parameter and the length of the Q parameter are not equal and the values of group parameters are also not constant.
can any one suggest me a way to solve this problem.
Thanks in advance.
|
|
|
|
|
Hi All,
when I build visual studio to create exe file .Then I run exe file ,It will have a process . and I continue to run exe file again . Therefore i will have two process for exe file .
How to Create Single Process in C++ ?
I think we can check process currently if process exist we exit new process.
I try to use singleton but i can not create single process.
Do you have any way ?
Thanks
Thong LT
|
|
|
|
|
|