diff --git a/C/init.c b/C/init.c index 031f15ba5..b21920970 100644 --- a/C/init.c +++ b/C/init.c @@ -1346,9 +1346,6 @@ InitVersion(void) } -#define K ((Int) 1024) - - void Yap_InitWorkspace(int Heap, int Stack, int Trail, int max_table_size, int n_workers, int sch_loop, int delay_load) diff --git a/C/threads.c b/C/threads.c index a995c5206..dab43607e 100644 --- a/C/threads.c +++ b/C/threads.c @@ -384,10 +384,16 @@ p_thread_destroy(void) static Int p_thread_detach(void) { - if (pthread_detach(ThreadHandle[IntegerOfTerm(Deref(ARG1))].handle) < 0) { + Int tid = IntegerOfTerm(Deref(ARG1)); + pthread_mutex_lock(&(ThreadHandle[tid].tlock)); + if (pthread_detach(ThreadHandle[tid].handle) < 0) { /* ERROR */ + pthread_mutex_unlock(&(ThreadHandle[tid].tlock)); return FALSE; } + ThreadHandle[tid].tdetach = + MkAtomTerm(AtomTrue); + pthread_mutex_unlock(&(ThreadHandle[tid].tlock)); return TRUE; } diff --git a/H/alloc.h b/H/alloc.h index 61de0878c..97d063a65 100644 --- a/H/alloc.h +++ b/H/alloc.h @@ -55,6 +55,8 @@ typedef struct FREEB { struct FREEB *b_next_size; } BlockHeader; +#define K ((Int) 1024) + #define MinBlockSize (sizeof(BlockHeader)+sizeof(YAP_SEG_SIZE)) #define MaxBlockSize 0xffffff #define InUseFlag 0x80000000 @@ -138,4 +140,3 @@ void Yap_add_memory_hole(ADDR, ADDR); #define SCRATCH_START_SIZE (64*1024L) #define SCRATCH_INC_SIZE (64*1024L) - diff --git a/library/dgraphs.yap b/library/dgraphs.yap index 282b37b7e..008911c21 100644 --- a/library/dgraphs.yap +++ b/library/dgraphs.yap @@ -31,8 +31,7 @@ dgraph_max_path/5, dgraph_min_paths/3, dgraph_isomorphic/4, - dgraph_path/3, - dgraph_connected_components]). + dgraph_path/3]). :- reexport(library(rbtrees), [rb_new/1 as dgraph_new]). diff --git a/library/undgraphs.yap b/library/undgraphs.yap index e13313bf6..4ab65576d 100644 --- a/library/undgraphs.yap +++ b/library/undgraphs.yap @@ -18,6 +18,7 @@ undgraph_neighbors/3, undgraph_neighbours/3, undgraph_complement/2, + undgraph_components/2, dgraph_to_undgraph/2, undgraph_min_tree/2]). @@ -58,6 +59,8 @@ :- use_module(library(rbtrees), [ rb_delete/4, + rb_insert/4, + rb_in/3, rb_partial_map/4 ]). @@ -160,4 +163,24 @@ undgraph_max_tree(G, T) :- wundgraph_max_tree(WG, WT, _), wundgraph_to_undgraph(WT, T). - +undgraph_components(Graph,[Map|Gs]) :- + pick_node(Graph,Node,Children,Graph1), !, + undgraph_new(Map0), + rb_insert(Map0, Node, Children, Map1), + expand_component(Children, Map1, Map, Graph1, NGraph), + undgraph_components(NGraph,Gs). +undgraph_components(_,[]). + +expand_component([], Map, Map, Graph, Graph). +expand_component([C|Children], Map1, Map, Graph1, NGraph) :- + rb_delete(Graph1, C, Edges, Graph2), !, + rb_insert(Map1, C, Edges, Map2), + expand_component(Children, Map2, Map3, Graph2, Graph3), + expand_component(Edges, Map3, Map, Graph3, NGraph). +expand_component([C|Children], Map1, Map, Graph1, NGraph) :- + expand_component(Children, Map1, Map, Graph3, NGraph). + + +pick_node(Graph,Node,Children,Graph1) :- + rb_in(Node,Children,Graph), !, + rb_delete(Graph, Node, Graph1).