Hi
I've an easy question but as I've never done such kind of code, I don't know how to do that.
I've a list of threads doing a specific treatment and each of them needs to insert an item (inside a wxlistctrl that is in the mainframe).
My problem is the following:
Each thread may insert an item at the same unexpected time but InsertItem() method of wxListCtrl will fail if index of item to be created already exist.
Thread1 inserts item1, item2 and Thread2 inserts also the item1, ...
I was thinking on a wxSemaphore to protect the number of already created items in the wxlistctrl (then when a thread will insert an item, we are sure the item doesn't exist) but I'm not sure it is the best solution
Any idea ?
Antonio
wxThreads and update of common variable Topic is solved
-
- Earned a small fee
- Posts: 19
- Joined: Sun Feb 18, 2007 11:45 pm
hi Antonio
In wxListCtrl, can't you just create the wxListItem item first - and add that straight without an index?
If that isn't viable - for whatever reason - you could aways do something like:
Obviously the first is far nicer.
Tim
In wxListCtrl, can't you just create the wxListItem item first - and add that straight without an index?
Code: Select all
wxListItem item();
item.SetText(wxT("String to be inserted"));
listCtrl->InsertItem(item);
Code: Select all
long l;
int index = 0;
do {
l = listCtrl->InsertItem(index, wxT("String to be inserted"));
index++;
} while (l != -1)
Tim
--
iBook G4 - OS X 10.4 - wxMac 2.8.0 - Compiling for Universal - g++
Toshiba Portege - 1.4 Ghz Centrino - Windows XP - wxMSW 2.8.0 - mingw
iBook G4 - OS X 10.4 - wxMac 2.8.0 - Compiling for Universal - g++
Toshiba Portege - 1.4 Ghz Centrino - Windows XP - wxMSW 2.8.0 - mingw