|
Hi everyone,
I am trying to use the boost multithreading library. I am having a
problem as the join() function for the thread never returns. I am using
a boolean variable to indicate when the thread should stop running.
Here is basically a stub of what I am doing:
<br />
bool m_RunThread = false;<br />
scoped_ptr<boost::thread> myThread;<br />
<br />
void MyObject::StartThread()<br />
{<br />
m_RunThread = true;<br />
myThread.reset(new boost::thread(boost::bind<br />
(&MyObject::MyThreadFunc, this)));<br />
}<br />
<br />
void MyObject::StopThread()<br />
{<br />
m_RunThread = false;<br />
myThread.join();
<br />
... Never gets here....<br />
<br />
}<br />
<br />
void MyObject::MyThreadFunc()<br />
{<br />
while (m_RunThread)<br />
{<br />
}<br />
}<br />
However, the join() function in StopThread never returns. I think that
using a variable to synchronize this is probably not a good idea. Any
thoughts and suggestions?
Cheers,
K
|
|
|
|
|
Have you verified that MyObject::MyThreadFunc ever exits? Perhaps it's spinning in a loop.
Steve
|
|
|
|
|
Yup. It definitely exits, as if you put a breakpoint in there after the condition is met, it never gets there. Also, m_RunThread member is declared as volatile.
Cheers,
K
|
|
|
|
|
Sorry, but I'm not sure if it exits or not after reading you reply. When you say, "It definitely exits" it makes me think it exits but when you say, "it never gets there" I'm not so sure. If you put a breakpoint at all return points of the thread function does one get hit?
Steve
|
|
|
|
|
Anyone know of an easy way to search a vector for the following:
Lets say I have a vector with 80,000 structures in it and I want to search for duplicate strDevice strings in each struct. Is there a easy or fast way to do this with out pulling the first string and compairing it to the other 79,999 then pulling the second and third etc...
const struct s_item
{
CString strDevice,
strIP,
strLID;
};
std::vector<s_item> v_items;
Any ideas?
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
you could add them to a std::map and in each node, keep the index of the std::vector of the string ...
for example ( with letters )
vector : a b c d a b a a c d e f a b
loop the vector, for each item, insert in the map
a (idx 0, 4, 6, 7, 12 )
b (idx 1, 5, 13 )
...
at the end, you have a map of all uniq words, with a vector of the index in the vector of each string ( or structure )
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
using stl::find() algorithm seems to work fine for me.
My articles
BlackDice
|
|
|
|
|
First you need a way of comparing s_item s for equality based on the strDevice string:
struct DeviceIDsEqual : binary_function<s_item, s_item, bool>
{
bool operator()(const s_item& f, const s_item& s) const
{
return f.strDevice == s.strDevice;
}
}
We also need the vector sorted so we need to compare if one s_item is less the another based on the strDevice string.
struct DeviceIDsLess : binary_function<s_item, s_item, bool>
{
bool operator()(const s_item& f, const s_item& s) const
{
return f.strDevice < s.strDevice;
}
}
Now we first sort then eliminate duplicates:
typedef vector<s_item>::iterator VI;
sort(v_items.begin(), v_items.end(), DeviceIDsLess());
VI newEnd = unique(v_items.begin(), v_items.end(), DeviceIDsEqual());
m_items.erase(newEnd, v_items.end());
Of if you just want to find the duplicates you can use the adjacent_find algorithm.
This code needs the following includes:
<functional>
<algorithm>
and the following:
using namespace std;
Steve
-- modified at 23:48 Monday 6th February, 2006
|
|
|
|
|
Thank you this is exactly what I was looking for. I need to brush up on templates and STL
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
My software has unicode display problem. I followed UNICODE articles from this site. But my software menu still can not display UNIcode under the English Win XP OS (Unicode font was installed. On the same computer, the notepad can display unicode. )
Any body has same experience and how you solved this problem?
Many thanks,
|
|
|
|
|
I am looking for some gauge controls like the Dundas gauges, but for MFC and not .NET.
Commercial is ok, but as always free would be better
Thanks
|
|
|
|
|
Hi All,
I remember seeing a call that would allow you to download a file via a url in MSDN, I can't for the life of me, remember what it was called.
Anybody know?
Thanks.
Mike
|
|
|
|
|
I think URLDownloadToCacheFile(...) and URLDownloadToFile(...) are what you are looking for. There is an article here on CP that demonstrates at least one of those functions.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
URLDownloadToFile
rrrado
|
|
|
|
|
I have a dialog MFC application. Sometimes I show the modeless dialog above parent dialog to display some progress of worker thread. Progress window can be currently moved along the screen. How to make it clipped by parent dialog ? (Something like a view window in the MDI Frame)
Thank you!
rrrado
|
|
|
|
|
By doing so you would be eliminating one of the features of a modeless dialog in this context - why not just show the progress on the underlying dialog and save yourself the trouble?
Anyway, you can handle WM_MOVE on the modeless dialog, and constrain its movement to the bounds of the parent window. This will not really clip the modeless dialog, but that too is not such a good idea because you would be allowing the user to effectively hide the modeless window, again eliminating one of the basic features of a modeless dialog.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
I cannot show it in underlying window because it contains big area which is useless when not working and there is not enough room in parent window for this.
I'm handling parent movement exactly as you've wrote but it allows to move it for example above right edge of parent and then move parent together with progress to right edge of desktop so progress will be hidden. I don't want to handle all such situations including minimizing window, etc.
There must be some easier sulution and I want to know it
For example WinRar shows progress this way and it looks good
rrrado
|
|
|
|
|
please don't ... me think it goes against good normal Microsoft's UI behaviour ..
BUT ... you could do something different ...
if your progress dialog is modeless and does not really show information ( apart from the progree ); add a status bar to your dialog application and and display the progress in there insted on a popup modeless dialog.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
When selecting an item in a listview I can only highlight the first item, not the entire row. Where´s the problem ?
int nItem = m_Liste.GetNextSelectedItem(pos);
m_Liste.SetItemState( nItem, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED);
m_Liste.EnsureVisible( nItem, FALSE);
|
|
|
|
|
Check LVS_EX_FULLROWSELECT extended style
rrrado
|
|
|
|
|
Set the LVS_EX_FULLROWSELECT extended style.
I Dream of Absolute Zero
|
|
|
|
|
Thanks for you response, but it didn´t help:
int nItem = m_Liste.GetNextSelectedItem(pos);
m_Liste.SetItemState( nItem, LVS_EX_FULLROWSELECT,
LVS_EX_FULLROWSELECT | LVIS_FOCUSED);
m_Liste.EnsureVisible( nItem, FALSE);
|
|
|
|
|
When your ListView control is first created or attached to (like in CDialog::OnInitDialog(...) ):
m_Liste.SetExtendedStyle( LVS_EX_FULLROWSELECT );
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
All right, I´ve got it. Thanks a lot.
m_Liste.SetExtendedStyle( LVS_EX_FULLROWSELECT);
POSITION pos;
pos = m_Liste.GetFirstSelectedItemPosition();
if( pos == NULL)
{
*pResult = 0;
return;
}
else
{
// Use the following to display an entire row as selected
// should you need to do so.
int nItem = m_Liste.GetNextSelectedItem(pos);
m_Liste.SetItemState( nItem, LVS_EX_FULLROWSELECT,
LVS_EX_FULLROWSELECT | LVIS_FOCUSED);
m_Liste.EnsureVisible( nItem, FALSE);
}
|
|
|
|
|
Anyone know of an easy to use timer for MFC. Just want to check the time it takes to execute two function calls.
Thanks
|
|
|
|