int main() { boost::signal2<void, int, int> sig; sig.connect(print_sum()); sig.connect(print_product()); sig(3, 5); boost::signals::connection print_diff_con = sig.connect(print_difference()); // sig is still connected to print_diff_con assert(print_diff_con.connected()); sig(5, 3); // prints 8, 15, and 2 print_diff_con.disconnect(); // disconnect the print_difference slot sig(5, 3); // now prints 8 and 15, but not the difference assert(!print_diff_con.connected()); // not connected any more { boost::signals::scoped_connection c = sig.connect(print_quotient()); sig(5, 3); // prints 8, 15, and 1 } // c falls out of scope, so sig and print_quotient are disconnected sig(5, 3); // prints 8 and 15 return 0; }
int main(void){ unsigned int digit = 10, limit = fact(10); unsigned int j,sum=0,hits=0; while(next_perm()){ if(unusual()){ results = realloc(results,(hits+1)*sizeof *results); results[hits] = malloc(len*sizeof *results[0]); memcpy(results[hits],perm,len*sizeof perm[0]); //printf("%d : ",j); printResult(results[hits]); hits++; } //next_perm(); } calc_sum(results,hits); print_sum(); //printf("sum is %d\n",sum); return 0; }
int main() { boost::signal2<void, int, int> sig; sig.connect(print_sum()); sig.connect(print_product()); sig(3, 5); boost::signals::connection print_diff_con = sig.connect(print_difference()); // sig is still connected to print_diff_con assert(print_diff_con.connected()); sig(5, 3); // prints 8, 15, and 2 print_diff_con.disconnect(); // disconnect the print_difference slot sig(5, 3); // now prints 8 and 15, but not the difference assert(!print_diff_con.connected()); // not connected any more return 0; }
int main(int argc, char *argv[]) { const char *errstr; char errbuf[_POSIX2_LINE_MAX], *kmem = NULL, *kernel = NULL; struct kinfo_proc *kproc; struct sum total_sum; int many, ch, rc; kvm_t *kd; pid_t pid = -1; gid_t gid; while ((ch = getopt(argc, argv, "AaD:dlmM:N:p:Prsvx")) != -1) { switch (ch) { case 'A': print_amap = 1; break; case 'a': print_all = 1; break; case 'd': print_ddb = 1; break; case 'D': debug = strtonum(optarg, 0, 0xf, &errstr); if (errstr) errx(1, "invalid debug mask"); break; case 'l': print_maps = 1; break; case 'm': print_map = 1; break; case 'M': kmem = optarg; break; case 'N': kernel = optarg; break; case 'p': pid = strtopid(optarg); break; case 'P': pid = getpid(); break; case 's': print_solaris = 1; break; case 'v': verbose = 1; break; case 'r': case 'x': errx(1, "-%c option not implemented, sorry", ch); /*NOTREACHED*/ default: usage(); } } /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ gid = getgid(); if (kernel != NULL || kmem != NULL) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); argc -= optind; argv += optind; /* more than one "process" to dump? */ many = (argc > 1 - (pid == -1 ? 0 : 1)) ? 1 : 0; /* apply default */ if (print_all + print_map + print_maps + print_solaris + print_ddb == 0) print_solaris = 1; /* start by opening libkvm */ kd = kvm_openfiles(kernel, kmem, NULL, O_RDONLY, errbuf); if (kernel == NULL && kmem == NULL) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); if (kd == NULL) errx(1, "%s", errbuf); /* get "bootstrap" addresses from kernel */ load_symbols(kd); memset(&total_sum, 0, sizeof(total_sum)); do { struct sum sum; memset(&sum, 0, sizeof(sum)); if (pid == -1) { if (argc == 0) pid = getppid(); else { pid = strtopid(argv[0]); argv++; argc--; } } /* find the process id */ if (pid == 0) kproc = NULL; else { kproc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &rc); if (kproc == NULL || rc == 0) { warnc(ESRCH, "%d", pid); pid = -1; continue; } } /* dump it */ if (many) { if (kproc) printf("process %d:\n", pid); else printf("kernel:\n"); } process_map(kd, pid, kproc, &sum); if (print_amap) print_sum(&sum, &total_sum); pid = -1; } while (argc > 0); if (print_amap) print_sum(&total_sum, NULL); /* done. go away. */ rc = kvm_close(kd); if (rc == -1) err(1, "kvm_close"); return (0); }