/srv/irclogs.ubuntu.com/2008/10/28/#upstart.txt

sadmac2Keybuk: for the lists, what if we swapped the prev and next pointers for cursors?15:27
sadmac2if list->next->prev != self (list->next is a cursor)15:28
Keybukhuh?15:30
sadmac2Keybuk: for cursors, cursor->next points to the previous element, and cursor->prev points to the next. We can detect this condition easily. if list->next->prev != list then list->next is a cursor15:31
Keybukthere's lots of ways like that15:32
Keybukbut they all invalidate the list in such a way that you can't just iterate on list->next15:32
sadmac2Keybuk: well, in the list head right now, the ordering is the only bit of information that isn't used15:35
sadmac2well, it is used, but that can be parted with15:35
Keybuk?15:36
sadmac2Keybuk: if you're serious about making this multithreaded one day, I suggest you just add the flag variable, because you're going to have to put a semaphore in the list head later anyway, so the space is going to get used.15:37
Keybukthe flag still means you have to know about cursors15:38
Keybukwhich means an nih_list_next () and nih_list_prev () function15:38
Keybuk(that know how to skip over them)15:38
sadmac2macros more like15:38
sadmac2and that's the nature of the problem15:38
sadmac2the stock linked list just doesn't display reentrant behavior15:38
Keybukthey have to be while loops15:38
Keybukwith a temporary variable at least15:39
Keybukfor (NihList *ptr = iter; ptr != iter && nih_list_is_cursor (ptr); ptr = ptr->next)15:40
Keybuk    ;15:40
sadmac2Keybuk: you're next solution, from what I can gather, is to drop linked lists altogether. I can solve these sorts of issues slightly better with an auto-array15:41
Keybukhow does that help?15:50
Keybukat the point you're not using a linked list, you're in strange territory that's rarely worth bothering with15:53
sadmac2what??17:07
sadmac2an auto array helps because next and prev can be calculated for items that have gone out of existence17:08
sadmac2prev for foo[i] is foo[i-1]17:08
sadmac2and I really don't think linked list are that special17:09
ion_#define NIH_LIST_FOREACH_SAFE(list, i)                      \17:32
ion_  for (NihList *_copy_##i = nih_list_dup (list), *_##i = 0; \17:32
ion_       *(int *)&_##i < 2; ++ *(int *)&_##i)                 \17:32
ion_    if (*(int *)&_##i == 1) nih_free (_copy_##i);           \17:32
ion_    else NIH_LIST_FOREACH (_copy_##i, i)17:32
ion_Wait. No, it wouldn’t work.17:34
ion_I didn’t think far enough. :-)17:40
Keybukheh, copy the list?17:55
Keybukhas the same basic problem, you can't free the current or next pointer17:55
sadmac2I don't think linked lists are right here17:56
Keybuksadmac2: any option has the same fundamental problem17:56
sadmac2Keybuk: Ordered vector + iterators listed in head structure fixes it17:57
Keybuk?!17:58
sadmac2remove(list, x) { list.values[x] = list.values[--list.size]; for( k in list.iters) { if k >= x; k-- } }17:58
sadmac2being able to iterate by an index number rather than a pointer has its advantages17:59
Keybukwhich means you can't reference from anywhere else17:59
Keybukbecause the pointer to the object changes17:59
Keybukso you have to refer by index *everywhere*17:59
KeybukJob * becomes guint32 job_idx17:59
sadmac2not quite everywhere18:00
sadmac2only where list location is relevant18:00
Keybukno, everywhere18:00
Keybukbecause the pointer will change if you move it in the array18:00
sadmac2Keybuk: ah, but you can still have a list head in the objects18:00
Keybukif you have a list head, then it's a linked list18:00
Keybuknot a vector18:00
sadmac2foojob->list_idx18:00
sadmac2the head contains a pointer to a parent list and its index number therein18:01
Keybukvectors are also insanely expensive to do inserts on18:01
sadmac2Keybuk: I just did it in O(1)18:01
Keybukit's O(len list)18:01
sadmac2Keybuk: its only expensive if you preserve order18:01
Keybukyour above was not O(1)18:02
sadmac2it was O(1 + num iters)18:02
Keybukwhich leaves holes in the list18:02
sadmac2no18:03
sadmac2to remove 1) remove last element 2) put it back on top of the element you want gone 3) count--18:03
Keybukthat doesn't preserve order18:03
sadmac2nope18:03
* Keybuk is writing an init daemon, not a STL18:04
sadmac2well you've seen all the defects of all the possible solutions18:04
sadmac2which one do you want to live with?18:04
Keybukhonestly, I don't have a problem with the solution we had before18:05
sadmac2which is?18:05
KeybukI still can't see why you're affected by it18:05
Keybukcache the next pointer18:05
sadmac2fix my segfaults plz18:06
Keybukyou haven't filed any bugs18:06
Keybuknor have you attached any core files18:06
Keybukor stack traces18:06
Keybuketc.18:06
sadmac2notting: can you help here^^18:07
nottingoof. basically, when exiting single user mode, we would get random crashes and segfaults18:08
nottingbut i don't have a trace with current code at the moment18:08
sadmac2notting: I don't think we've pushed anything new since 0.5.0 that would change this, and since it seems to be race-related, probably best to reproduce it on the code that failed18:09
* sadmac2 goes to class18:11
Keybukthis is much easier in a reference/gc language :)18:21
nottinginit.js18:26
Keybukinit.cs18:27
Keybukthe real problem is just that the nih main loop code sucks18:30
Keybukif I fix that, then the "best way to line up a series of data structures" debate goes away :p18:30
ion_Switch to... glib!18:31
* ion_ ducks18:31
Keybuktempting18:34
sadmac2Keybuk: I'm pretty sure we fixed the main looop19:41
sadmac2we were getting an analogous issue elsewhere19:41
sadmac2the fix wasn't great I grant you, but I think that instance of the bug went away19:42
Keybukgiven the main loop is the only place this pattern is used, it might simply be not in the loop functions19:42
Keybukie in the timer or child or signal code19:42
Keybukby "fix the main loop" I include those19:42
sadmac2Keybuk: the other option is to do your multiparent allocator and fix it that way19:42
KeybukI believe by doing both, I can eliminate all uses of _SAFE in the first place19:43
sadmac2Keybuk: i.e. instead of caching the next pointer, the loop simply becomes a parent as it iterates19:43
sadmac2yes19:43
=== Keybuk_ is now known as Keybuk

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!