многонитковость, списки, очереди, файлы
This commit is contained in:
parent
290a99e0ee
commit
8a8bb95fd9
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
export ID_WIN="$(xwininfo | grep "Window id" | cut -d\" -f2)"
|
||||
echo $ID_WIN
|
||||
x=1
|
||||
wmctrl -r "$ID_WIN" -e 1,-1,-1,1,1;
|
||||
time for i in `seq 1024`;do (( x++ ));wmctrl -r "$ID_WIN" -e 1,0,0,$x,$x;done
|
||||
|
Binary file not shown.
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 65536; i++)
|
||||
if (!fopen("fopen_too_many_files.c", "rb")) {
|
||||
printf("ulimit = %d\n", i);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Hello, world!\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,16 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int a;
|
||||
|
||||
for (a = 0; a < 3; a++)
|
||||
fork();
|
||||
|
||||
printf("%lu\n", (unsigned long)&a);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# Makefile for generic linked list examples.
|
||||
#
|
||||
# Last edited: Tue Jul 28 15:36:13 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
#
|
||||
# Copyright (C) 1992 Bradley C. Spatz, bcs@ufl.edu
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
#
|
||||
#CC = /local/bin/gcc
|
||||
#CFLAGS = $(INCLUDES) -fstrength-reduce -finline-functions
|
||||
PACKAGE_VERSION=2.3.1
|
||||
CFLAGS += $(INCLUDES)
|
||||
INCLUDES= -I..
|
||||
LIBS = -L.. -llist
|
||||
#LIBS = -L .. -llist # Use this for HP-UX; great loader guys!
|
||||
#add macro for ranlib 4/96 *kob* - ranlib doesn't exist on solaris
|
||||
RANLIB = ls
|
||||
#
|
||||
all: listtest queuetest stacktest
|
||||
(cd cache; make)
|
||||
|
||||
listtest: listtest.o ../liblist.a
|
||||
$(CC) $(CFLAGS) -o listtest listtest.o $(LIBS)
|
||||
|
||||
queuetest: queuetest.o ../liblist.a
|
||||
$(CC) $(CFLAGS) -o queuetest queuetest.o $(LIBS)
|
||||
|
||||
stacktest: stacktest.o ../liblist.a
|
||||
$(CC) $(CFLAGS) -o stacktest stacktest.o $(LIBS)
|
||||
|
||||
listtest.o: ../list.h
|
||||
queuetest.o: ../queue.h
|
||||
stacktest.o: ../stack.h
|
||||
clean:
|
||||
rm -f listtest queuetest stacktest *.o core
|
||||
(cd cache; make clean)
|
|
@ -0,0 +1,146 @@
|
|||
/* cache.c -- routines to implement a generic, list(3)-based cache package.
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:41:47 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*
|
||||
* We define the following routines here:
|
||||
*
|
||||
* CACHE *cache_init(max_elements)
|
||||
* char *cache_enter(cache, data, bytes, removed)
|
||||
* char *cache_check(cache, data, match)
|
||||
* void cache_free(cache, dealloc)
|
||||
*
|
||||
* for
|
||||
*
|
||||
* CACHE *cache;
|
||||
* char *data;
|
||||
* int max_elements, max_size, bytes;
|
||||
* char **removed;
|
||||
* int match(data, curr)
|
||||
* char *data;
|
||||
* char *curr;
|
||||
* void dealloc(data)
|
||||
* char *data;
|
||||
*
|
||||
* We base this package on the list(3) package.
|
||||
*
|
||||
* Keep a data structure that is essentially a list. We'll add new
|
||||
* elements to the front of the list and remove old elements from the end
|
||||
* of the list. We'll optimize searches for MRU (Most Recently Used) and
|
||||
* we'll dispose of elements when we need space by using LRU. Finally,
|
||||
* we'll always promote the element on a hit to the front of the list.
|
||||
*
|
||||
* We'll allow the user to control the size of the cache in terms of
|
||||
* cache elements. This limit will be determined at cache creation.
|
||||
*/
|
||||
|
||||
static char brag[] = "$$Version: cache " "PACKAGE_VERSION" " Copyright (C) 1992 Bradley C. Spatz";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "cache.h"
|
||||
|
||||
CACHE *cache_init(int max_elements)
|
||||
{
|
||||
CACHE *new_cache;
|
||||
|
||||
/* Allocate, initialize, and return a new cache. Return NULL if
|
||||
* the malloc or list initialization fails.
|
||||
*/
|
||||
if ((new_cache = (CACHE *) malloc(sizeof(CACHE))) == NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
new_cache->max_elements = max_elements;
|
||||
if ((new_cache->list = list_init()) == NULL) {
|
||||
/* The list creation fragged, so release the cache descriptor. */
|
||||
free(new_cache);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(new_cache);
|
||||
}
|
||||
|
||||
|
||||
void *cache_enter(CACHE *cache, void *data, int bytes, void **removed)
|
||||
{
|
||||
char *new_element;
|
||||
|
||||
/* Add a new element to the front of our list. This is easy, because
|
||||
* we're using the list(3) package; our intentions exactly.
|
||||
* Try and add the new element. If that succeeds, then check for a
|
||||
* full cache. If full, remove the element at the rear of the list.
|
||||
* We return a pointer to the newly inserted element or NULL if the
|
||||
* insert failed. We also return a pointer to the removed element
|
||||
* if we did indeed remove one.
|
||||
*/
|
||||
*removed = NULL;
|
||||
new_element = list_insert_before(cache->list, data, bytes);
|
||||
if (new_element != NULL) {
|
||||
if (list_size(cache->list) > cache->max_elements) {
|
||||
*removed = (char *) list_remove_rear(cache->list);
|
||||
}
|
||||
}
|
||||
|
||||
return(new_element);
|
||||
}
|
||||
|
||||
|
||||
void *cache_check(CACHE *cache, void *data, cache_match_func_t match)
|
||||
{
|
||||
char *found;
|
||||
|
||||
/* Check for an empty cache. */
|
||||
if (list_size(cache->list) == 0) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Ok. Search the list for the element, starting from the front
|
||||
* of our list. If the traversal finds the element, then promote it to
|
||||
* the front if it's not already there, and return a pointer to the element.
|
||||
* Otherwise, return NULL. In either case, make sure to reset the
|
||||
* current element pointer back to the front of the list.
|
||||
*/
|
||||
if (list_traverse(cache->list, data, match,
|
||||
(LIST_FRNT | LIST_FORW | LIST_ALTR)) == LIST_OK) {
|
||||
/* We found what we're looking for. */
|
||||
if (list_curr(cache->list) != list_front(cache->list)) {
|
||||
fprintf(stderr, "cache_check: moving found to front.\n");
|
||||
found = (char *) list_remove_curr(cache->list);
|
||||
list_mvfront(cache->list);
|
||||
list_insert_before(cache->list, found, 0);
|
||||
return(found);
|
||||
}
|
||||
else {
|
||||
return(list_front(cache->list));
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* We did not find the element. */
|
||||
list_mvfront(cache->list);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cache_free(CACHE *cache, cache_dealloc_func_t dealloc)
|
||||
{
|
||||
/* First free up the list, and then the cache descriptor. */
|
||||
list_free(cache->list, dealloc);
|
||||
free(cache);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,131 @@
|
|||
/* cachetest.c -- test program for generic cache package
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:42:57 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
static char brag[] = "$$Version: cachetest " "PACKAGE_VERSION" " Copyright (C) 1992 Bradley C. Spatz";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "cache.h"
|
||||
|
||||
#define MAX_ELEMENTS 3
|
||||
|
||||
int match();
|
||||
|
||||
main()
|
||||
{
|
||||
CACHE *cache;
|
||||
char cmd[2];
|
||||
int val, *pval;
|
||||
|
||||
/* Print some instructions. */
|
||||
printf("This program demonstrates the various cache manipulation\n");
|
||||
printf("routines supplied by this package. Although this program\n");
|
||||
printf("manipulates a cache of integers, data of any type and size\n");
|
||||
printf("(and not just integers) are supported by the routines. See\n");
|
||||
printf("the man page for more information.\n\n");
|
||||
printf("We illustrate a cache with a maximum size of 3 entries.\n\n");
|
||||
|
||||
/* Allocate a new cache. */
|
||||
cache = cache_init(MAX_ELEMENTS);
|
||||
print_cache(cache);
|
||||
|
||||
/* Get some commands. */
|
||||
printf("\n(e)nter new element, (c)heck for element; (q)uit: ");
|
||||
while (scanf("%1s", cmd) != EOF) {
|
||||
switch (cmd[0]) {
|
||||
case 'e':
|
||||
printf("Value (int) to enter: ");
|
||||
if (scanf("%d", &val)) {
|
||||
/* We ignore the return code here, but in practice,
|
||||
* we may fail (with a return code of NULL).
|
||||
*/
|
||||
cache_enter(cache, &val, sizeof(val), (void **)&pval);
|
||||
if (pval != NULL) {
|
||||
printf("%d was removed to make room.\n", *pval);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
printf("Value (int) to check for: ");
|
||||
if (scanf("%d", &val)) {
|
||||
pval = (int *) cache_check(cache, (char *) &val, match);
|
||||
if (pval != NULL) {
|
||||
printf("%d found!\n", *pval);
|
||||
}
|
||||
else {
|
||||
printf("Not found.\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
cache_free(cache, CACHE_DEALLOC);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
printf("'%s' not a recognized command!\n", cmd);
|
||||
break;
|
||||
}
|
||||
print_cache(cache);
|
||||
printf("\n(e)nter new element, (c)heck for element; (q)uit: ");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/* Provide a routine to return FALSE (0) if the current element in the cache,
|
||||
* curr, is equal to the element we are searching for, data. We return
|
||||
* FALSE, instead of TRUE, because we will use the list_traverse function.
|
||||
* That function continues if the user-supplied function is TRUE. We want
|
||||
* to stop when we've found our element.
|
||||
*/
|
||||
int match(data, curr)
|
||||
char *data;
|
||||
char *curr;
|
||||
{
|
||||
return(((*(int *) data) == (*(int *) curr)) ? FALSE : TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* The following routines make know that the cache is implemented with
|
||||
* the list(3) package. It makes knowledge of the CACHE structure as
|
||||
* well. We do this here for illustration only.
|
||||
*/
|
||||
int print_element(input, curr)
|
||||
char *input;
|
||||
char *curr;
|
||||
{
|
||||
printf(" %d", *(int *) curr);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
print_cache(cache)
|
||||
CACHE *cache;
|
||||
{
|
||||
printf("Cache:");
|
||||
if (list_empty(cache->list))
|
||||
printf(" (empty).\n");
|
||||
else {
|
||||
list_traverse(cache->list, (char *) 0, print_element,
|
||||
(LIST_FRNT | LIST_FORW | LIST_SAVE));
|
||||
printf(".\n");
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,287 @@
|
|||
/* listtest.c -- test program for generic list package
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:37:21 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
static char brag[] = "$$Version: listtest " "PACKAGE_VERSION" " Copyright (C) 1992 Bradley C. Spatz";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../list.h"
|
||||
|
||||
main()
|
||||
{
|
||||
LIST *list;
|
||||
char cmd[2];
|
||||
int val, *pval;
|
||||
|
||||
/* Print some instructions. */
|
||||
printf("This program demonstrates the various list manipulation\n");
|
||||
printf("routines supplied by this package. Although this program\n");
|
||||
printf("manipulates a list of integers, data of any type and size\n");
|
||||
printf("(and not just integers) are supported by the routines. See\n");
|
||||
printf("the man page for more information.\n\n");
|
||||
|
||||
/* Allocate a new list. */
|
||||
list = list_init();
|
||||
printf("Curr = (nil).\n");
|
||||
print_list(list);
|
||||
|
||||
/* Get some commands. */
|
||||
printf("\n(i)nsert, (r)emove; (m)ove, (f)ront/r(e)ear, (t)raverse, (s)ize, (q)uit: ");
|
||||
while (scanf("%1s", cmd) != EOF) {
|
||||
switch (cmd[0]) {
|
||||
case 'i':
|
||||
do_insert(list);
|
||||
break;
|
||||
case 'r':
|
||||
do_remove(list);
|
||||
break;
|
||||
case 'm':
|
||||
do_move(list);
|
||||
break;
|
||||
case 'f':
|
||||
pval = (int *) list_front(list);
|
||||
if (pval == NULL)
|
||||
printf("Front = (nil)\n");
|
||||
else
|
||||
printf("Front = %d\n", *pval);
|
||||
break;
|
||||
case 'e':
|
||||
pval = (int *) list_rear(list);
|
||||
if (pval == NULL)
|
||||
printf("Rear = (nil)\n");
|
||||
else
|
||||
printf("Rear = %d\n", *pval);
|
||||
break;
|
||||
case 't':
|
||||
do_traverse(list);
|
||||
break;
|
||||
case 's':
|
||||
printf("List has %d elements.\n", list_size(list));
|
||||
break;
|
||||
case 'q':
|
||||
list_free(list, LIST_DEALLOC);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
printf("'%s' not a recognized command!\n", cmd);
|
||||
break;
|
||||
}
|
||||
pval = (int *) list_curr(list);
|
||||
if (pval == NULL)
|
||||
printf("Curr = (nil)\n");
|
||||
else
|
||||
printf("Curr = %d\n", *pval);
|
||||
print_list(list);
|
||||
printf("\n(i)nsert, (r)emove; (m)ove, (f)ront/r(e)ear, (t)raverse, (s)ize, (q)uit: ");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
do_insert(list)
|
||||
LIST *list;
|
||||
{
|
||||
char cmd[2];
|
||||
int val, *bogus;
|
||||
|
||||
printf("insert (b)efore or (a)after: ");
|
||||
scanf("%1s", cmd);
|
||||
switch (cmd[0]) {
|
||||
case 'b':
|
||||
printf("Value (int) to insert before: ");
|
||||
if (scanf("%d", &val))
|
||||
/* We ignore the return code here, but in practice,
|
||||
* we may fail (with a return code of NULL).
|
||||
*/
|
||||
list_insert_before(list, &val, sizeof(val));
|
||||
break;
|
||||
case 'a':
|
||||
printf("Value (int) to insert after: ");
|
||||
if (scanf("%d", &val))
|
||||
/* We ignore the return code here, but in practice,
|
||||
* we may fail (with a return code of NULL).
|
||||
*/
|
||||
list_insert_after(list, &val, sizeof(val));
|
||||
break;
|
||||
default:
|
||||
printf("%c not recognized. Returning to main menu.\n", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
do_remove(list)
|
||||
LIST *list;
|
||||
{
|
||||
char cmd[2];
|
||||
int *pval;
|
||||
|
||||
printf("remove (f)ront, (c)urr, or (r)ear: ");
|
||||
scanf("%1s", cmd);
|
||||
switch (cmd[0]) {
|
||||
case 'f':
|
||||
pval = (int *) list_remove_front(list);
|
||||
break;
|
||||
case 'c':
|
||||
pval = (int *) list_remove_curr(list);
|
||||
break;
|
||||
case 'r':
|
||||
pval = (int *) list_remove_rear(list);
|
||||
break;
|
||||
default:
|
||||
printf("%c not recognized. Returning to main menu.\n", cmd[0]);
|
||||
}
|
||||
|
||||
if (pval == NULL)
|
||||
printf("List is empty!\n");
|
||||
else
|
||||
printf("%d removed.\n", *pval);
|
||||
}
|
||||
|
||||
|
||||
do_move(list)
|
||||
LIST *list;
|
||||
{
|
||||
char cmd[2];
|
||||
|
||||
printf("move to (p)revious, (n)ext, (f)ront, or (r)ear: ");
|
||||
scanf("%1s", cmd);
|
||||
switch (cmd[0]) {
|
||||
case 'p':
|
||||
if (list_mvprev(list) == NULL)
|
||||
printf("No previous element!\n");
|
||||
break;
|
||||
case 'n':
|
||||
if (list_mvnext(list) == NULL)
|
||||
printf("No next element!\n");
|
||||
break;
|
||||
case 'f':
|
||||
/* We ignore the return code here. */
|
||||
list_mvfront(list);
|
||||
break;
|
||||
case 'r':
|
||||
/* We ignore the return code here. */
|
||||
list_mvrear(list);
|
||||
break;
|
||||
default:
|
||||
printf("%c not recognized. Returning to main menu.\n", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Routine to print the integer stored at each node. In this example,
|
||||
* we ignore the first parameter, which might be useful if we were
|
||||
* searching the list or something. We must return 0 or 1, so we always
|
||||
* return 1.
|
||||
*/
|
||||
int print_element(input, curr)
|
||||
char *input;
|
||||
char *curr;
|
||||
{
|
||||
printf(" %d", *(int *) curr);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
do_traverse(list)
|
||||
LIST *list;
|
||||
{
|
||||
char cmd[2];
|
||||
int opts=0, rc;
|
||||
|
||||
printf("traverse from (f)ront, (r)ear, or (c)urrent element: ");
|
||||
scanf("%1s", cmd);
|
||||
switch (cmd[0]) {
|
||||
case 'f':
|
||||
opts = (opts | LIST_FRNT);
|
||||
break;
|
||||
case 'r':
|
||||
opts = (opts | LIST_REAR);
|
||||
break;
|
||||
case 'c':
|
||||
opts = (opts | LIST_CURR);
|
||||
break;
|
||||
default:
|
||||
printf("%c not recognized. Returning to main menu.\n", cmd[0]);
|
||||
}
|
||||
|
||||
if (cmd[0] == 'c') {
|
||||
printf("traverse (f)orwards or (b)ackwards: ");
|
||||
scanf("%1s", cmd);
|
||||
switch (cmd[0]) {
|
||||
case 'f':
|
||||
opts = (opts | LIST_FORW);
|
||||
break;
|
||||
case 'b':
|
||||
opts = (opts | LIST_BACK);
|
||||
break;
|
||||
default:
|
||||
printf("%c not recognized. Returning to main menu.\n", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("(a)lter or (p)reserve the current element pointer: ");
|
||||
scanf("%1s", cmd);
|
||||
switch (cmd[0]) {
|
||||
case 'a':
|
||||
opts = (opts | LIST_ALTR);
|
||||
break;
|
||||
case 'p':
|
||||
opts = (opts | LIST_SAVE);
|
||||
break;
|
||||
default:
|
||||
printf("%c not recognized. Returning to main menu.\n", cmd[0]);
|
||||
}
|
||||
|
||||
printf("Traversal: ");
|
||||
rc = list_traverse(list, (char *) 0, print_element, opts);
|
||||
switch (rc) {
|
||||
case LIST_EMPTY:
|
||||
printf("(empty).\n");
|
||||
break;
|
||||
case LIST_OK:
|
||||
printf(".\n");
|
||||
break;
|
||||
case LIST_EXTENT:
|
||||
printf(". (extent reached)\n");
|
||||
break;
|
||||
default:
|
||||
printf("%c not recognized. Returning to main menu.\n", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Routine to print a list of integers, using the traversal function.
|
||||
* In this example, we send NULL for the second parameter, which might be
|
||||
* used to specify an element to search for.
|
||||
*/
|
||||
print_list(list)
|
||||
LIST *list;
|
||||
{
|
||||
printf("List:");
|
||||
if (list_empty(list))
|
||||
printf(" (empty).\n");
|
||||
else {
|
||||
list_traverse(list, (char *) 0, print_element,
|
||||
(LIST_FRNT | LIST_FORW | LIST_SAVE));
|
||||
printf(".\n");
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,120 @@
|
|||
/* queuetest.c -- test program for generic queue package.
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:38:58 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
static char brag[] = "$$Version: queuetest " "PACKAGE_VERSION" " Copyright (C) 1992 Bradley C. Spatz";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../queue.h"
|
||||
|
||||
main()
|
||||
{
|
||||
QUEUE *q;
|
||||
char cmd;
|
||||
int val, *pval;
|
||||
|
||||
/* Print some instructions. */
|
||||
printf("This program demonstrates the various queue manipulation\n");
|
||||
printf("routines supplied by this package. Although this program\n");
|
||||
printf("manipulates a queue of integers, data of any type and size\n");
|
||||
printf("(and not just integers) are supported by the routines. See\n");
|
||||
printf("the man page for more information.\n\n");
|
||||
|
||||
/* Allocate a new queue. */
|
||||
q = q_init();
|
||||
print_queue(q);
|
||||
|
||||
/* Get some commands. */
|
||||
printf("(e)nqueue, (d)equeue, (f)ront, (s)ize, (c)heck, (q)uit: ");
|
||||
while (scanf("%1s", &cmd) != EOF) {
|
||||
switch (cmd) {
|
||||
case 'e':
|
||||
printf("Value (int) to enqueue: ");
|
||||
if (scanf("%d", &val))
|
||||
/* We ignore the return code here, butin practice, we may
|
||||
* fail (with a return code of 0).
|
||||
*/
|
||||
q_enqueue(q, &val, sizeof(val));
|
||||
break;
|
||||
case 'd':
|
||||
pval = (int *) q_dequeue(q);
|
||||
if (pval != NULL)
|
||||
printf("%d dequeued.\n", *pval);
|
||||
else
|
||||
printf("Queue is empty!\n");
|
||||
break;
|
||||
case 'f':
|
||||
pval = (int *) q_front(q);
|
||||
if (pval == NULL)
|
||||
printf("Queue is empty!\n");
|
||||
else
|
||||
printf("%d at front.\n", *pval);
|
||||
break;
|
||||
case 's':
|
||||
val = q_size(q);
|
||||
printf("Queue has %d element%s.\n", val, ((val == 1) ? "" : "s"));
|
||||
break;
|
||||
case 'c':
|
||||
printf("Queue is%s empty.\n", (q_empty(q) ? "" : " not"));
|
||||
break;
|
||||
case 'q':
|
||||
q_free(q, QUEUE_DEALLOC);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
printf("'%c' not a recognized command!\n", cmd);
|
||||
break;
|
||||
}
|
||||
print_queue(q);
|
||||
printf("\n(e)nqueue, (d)equeue, (f)ront, (s)ize, (c)heck, (q)uit: ");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/* Routine to print the integer stored at each node. In this example,
|
||||
* we ignore the first parameter, which might be useful if we were
|
||||
* searching the list or something. We must return 0 or 1, so we always
|
||||
* return 1.
|
||||
*/
|
||||
int print_element(input, curr)
|
||||
char *input;
|
||||
char *curr;
|
||||
{
|
||||
printf(" %d", *(int *) curr);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* Routine to print a queue of integers. */
|
||||
print_queue(queue)
|
||||
QUEUE *queue;
|
||||
{
|
||||
printf("Queue: ");
|
||||
if (q_empty(queue))
|
||||
printf("(empty)\n");
|
||||
else {
|
||||
list_traverse(queue, (char *) 0, print_element,
|
||||
(LIST_FRNT | LIST_FORW | LIST_SAVE));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,120 @@
|
|||
/* stacktest.c -- test program for generic stack package
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:38:19 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
static char brag[] = "$$Version: stacktest " "PACKAGE_VERSION" " Copyright (C) 1992 Bradley C. Spatz";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../stack.h"
|
||||
|
||||
main()
|
||||
{
|
||||
STACK *stack;
|
||||
char cmd;
|
||||
int val, *pval;
|
||||
|
||||
/* Print some instructions. */
|
||||
printf("This program demonstrates the various stack manipulation\n");
|
||||
printf("routines supplied by this package. Although this program\n");
|
||||
printf("manipulates a stack of integers, data of any type and size\n");
|
||||
printf("(and not just integers) are supported by the routines. See\n");
|
||||
printf("the man page for more information.\n\n");
|
||||
|
||||
/* Allocate a new stack. */
|
||||
stack = stack_init();
|
||||
print_stack(stack);
|
||||
|
||||
/* Get some commands. */
|
||||
printf("(p)ush, p(o)p, (t)op, (s)ize, (c)heck, (q)uit: ");
|
||||
while (scanf("%1s", &cmd) != EOF) {
|
||||
switch (cmd) {
|
||||
case 'p':
|
||||
printf("Value (int) to push: ");
|
||||
if (scanf("%d", &val))
|
||||
/* We ignore the return code here, but in practice, we may
|
||||
* fail (with a return code of NULL).
|
||||
*/
|
||||
stack_push(stack, &val, sizeof(val));
|
||||
break;
|
||||
case 'o':
|
||||
pval = (int *) stack_pop(stack);
|
||||
if (pval != NULL)
|
||||
printf("%d popped.\n", *pval);
|
||||
else
|
||||
printf("Stack is empty!\n");
|
||||
break;
|
||||
case 't':
|
||||
pval = (int *) stack_top(stack);
|
||||
if (pval == NULL)
|
||||
printf("Stack is empty!\n");
|
||||
else
|
||||
printf("%d on top.\n", *pval);
|
||||
break;
|
||||
case 's':
|
||||
val = stack_size(stack);
|
||||
printf("Stack has %d element%s.\n", val, ((val == 1) ? "":"s"));
|
||||
break;
|
||||
case 'c':
|
||||
printf("Stack is%s empty.\n", (stack_empty(stack) ? "" : " not"));
|
||||
break;
|
||||
case 'q':
|
||||
stack_free(stack, STACK_DEALLOC);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
printf("'%c' not a recognized command!\n", cmd);
|
||||
break;
|
||||
}
|
||||
print_stack(stack);
|
||||
printf("\n(p)ush, p(o)p, (t)op, (s)ize, (c)heck, (q)uit: ");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/* Routine to print the integer stored at each node. In this example,
|
||||
* we ignore the first parameter, which might be useful if we were
|
||||
* searching the list or something. We must return 0 or 1, so we always
|
||||
* return 1.
|
||||
*/
|
||||
int print_element(input, curr)
|
||||
char *input;
|
||||
char *curr;
|
||||
{
|
||||
printf(" %d", *(int *) curr);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* Routine to print a stack of integers. */
|
||||
print_stack(stack)
|
||||
STACK *stack;
|
||||
{
|
||||
printf("Stack: ");
|
||||
if (stack_empty(stack))
|
||||
printf("(empty)\n");
|
||||
else {
|
||||
list_traverse(stack, (char *) 0, print_element,
|
||||
(LIST_FRNT | LIST_FORW | LIST_SAVE));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/* list.h -- data structures and such for generic list package
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:29:56 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
* Updated by Nathan Phillip Brink 2010
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LIBLIST_LIST_H
|
||||
#define _LIBLIST_LIST_H
|
||||
|
||||
#include <list_namespace.h>
|
||||
|
||||
/* Define a structure to describe the list. */
|
||||
struct list;
|
||||
typedef struct list *list_t;
|
||||
|
||||
/* Define a structure to describe each element in the list. */
|
||||
struct list_element;
|
||||
typedef struct list_element *list_element_t;
|
||||
|
||||
/*
|
||||
Backwards API compatibility plug.
|
||||
We're willing to make the API as backwards-compatible as possible
|
||||
but we are going to enforce opaque handles, eliminating the macros
|
||||
instead of functions option.
|
||||
*/
|
||||
#define LIST_ELEMENT struct list_element
|
||||
#define LIST struct list
|
||||
|
||||
typedef int (*list_traverse_func_t)(void *data, void *node_data);
|
||||
typedef void (*list_dealloc_func_t)(void *);
|
||||
|
||||
/**
|
||||
A default data-freeing function for the LIST_DEALLOC.
|
||||
*/
|
||||
void list_free_free(void *);
|
||||
|
||||
/* Prototype ahoy! */
|
||||
list_t list_init();
|
||||
list_t list_mvprev(list_t);
|
||||
list_t list_mvnext(list_t);
|
||||
void *list_insert_before(list_t, void *data, int len);
|
||||
void *list_insert_after(list_t, void *data, int len);
|
||||
void *list_remove_front(list_t);
|
||||
void *list_remove_rear(list_t);
|
||||
void *list_remove_curr(list_t);
|
||||
void list_free(list_t, list_dealloc_func_t);
|
||||
|
||||
/* Define some constants for controlling list traversals. We
|
||||
* bit-code the attributes so they can be OR'd together.
|
||||
*/
|
||||
#define LIST_FORW 0
|
||||
#define LIST_BACK 2
|
||||
#define LIST_FRNT 4
|
||||
#define LIST_CURR 8
|
||||
#define LIST_REAR (16 | LIST_BACK) /* 16 + 2, since REAR implies BACKwards. */
|
||||
#define LIST_SAVE 32
|
||||
#define LIST_ALTR 64
|
||||
|
||||
/* Define some constants for return codes and such. */
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#define LIST_DEALLOC (&list_free_free)
|
||||
#define LIST_NODEALLOC (list_dealloc_func_t)NULL
|
||||
#define LIST_EMPTY 0
|
||||
#define LIST_OK 1
|
||||
#define LIST_EXTENT 2
|
||||
|
||||
/* Yet more prototypes. */
|
||||
void *list_front(list_t);
|
||||
void *list_curr(list_t);
|
||||
void *list_rear(list_t);
|
||||
list_t list_mvfront(list_t);
|
||||
list_t list_mvrear(list_t);
|
||||
|
||||
int list_empty(list_t);
|
||||
int list_size(list_t);
|
||||
|
||||
int list_traverse(list_t list, void *data, list_traverse_func_t func, int opts);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/* queue.h -- present queue abstraction with list primitives.
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:34:15 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _LIBLIST_QUEUE_H
|
||||
#define _LIBLIST_QUEUE_H
|
||||
|
||||
#include <list.h>
|
||||
|
||||
/* define queue objects in terms of list */
|
||||
#define queue_t list_t
|
||||
#define queue_element_t list_element_t
|
||||
|
||||
/* backwards compatibility */
|
||||
#define QUEUE LIST
|
||||
#define QUEUE_ELEMENT LIST_ELEMENT
|
||||
|
||||
/* Now map the queue functions onto the list primitives. The current
|
||||
* element pointer will always point to the end of the list, which is
|
||||
* where we add new elements. We remove elements from the front.
|
||||
* With this model, we map onto the list primitives directly.
|
||||
*/
|
||||
#define q_init() list_init()
|
||||
#define q_enqueue(queue, data, bytes) list_insert_after(queue, data, bytes)
|
||||
#define q_dequeue(queue) list_remove_front(queue)
|
||||
#define q_front(queue) list_front(queue)
|
||||
#define q_size(queue) list_size(queue)
|
||||
#define q_empty(queue) list_empty(queue)
|
||||
#define q_free(queue, dealloc) list_free(queue, dealloc)
|
||||
|
||||
/* Define the deallocation constants. */
|
||||
#define QUEUE_DEALLOC LIST_DEALLOC
|
||||
#define QUEUE_NODEALLOC LIST_NODEALLOC
|
||||
|
||||
#endif /* _LIBLIST_QUEUE_H */
|
|
@ -0,0 +1,52 @@
|
|||
/* stack.h -- present stack abstraction with list primitives.
|
||||
*
|
||||
* Last edited: Tue Jul 28 15:33:54 1992 by bcs (Bradley C. Spatz) on wasp
|
||||
*
|
||||
* Copyright (C) 1992, Bradley C. Spatz, bcs@ufl.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _LIBLIST_STACK_H
|
||||
#define _LIBLIST_STACK_H
|
||||
|
||||
#include <list.h>
|
||||
|
||||
/* Present the stack datatypes in terms of list types (our point exactly). */
|
||||
#define stack_t list_t
|
||||
#define stack_element_t list_element_t
|
||||
|
||||
/* Backwards compatibility */
|
||||
#define STACK LIST
|
||||
#define STACK_ELEMENT LIST_ELEMENT
|
||||
|
||||
/* Now map the stack functions onto the list primitives. The current
|
||||
* element pointer will always point to front of the list, which is
|
||||
* where we push and pop. With this model, we can map into the list
|
||||
* primitives directly.
|
||||
*/
|
||||
#define stack_init() list_init()
|
||||
#define stack_push(stack, data, bytes) list_insert_before(stack, data, bytes)
|
||||
#define stack_pop(stack) list_remove_front(stack)
|
||||
#define stack_top(stack) list_front(stack)
|
||||
#define stack_size(stack) list_size(stack)
|
||||
#define stack_empty(stack) list_empty(stack)
|
||||
#define stack_free(stack, dealloc) list_free(stack, dealloc)
|
||||
|
||||
/* Define the deallocation constants. */
|
||||
#define STACK_DEALLOC LIST_DEALLOC
|
||||
#define STACK_NODEALLOC LIST_NODEALLOC
|
||||
|
||||
#endif /* _LIBLIST_STACK_H */
|
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/list.h>
|
||||
|
||||
struct mystruct {
|
||||
int data;
|
||||
struct list_head mylist;
|
||||
};
|
||||
|
||||
struct mystruct first = {
|
||||
.data = 10,
|
||||
.mylist = LIST_HEAD_INIT(first.mylist)
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace boost;
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
static void Process_Files(const path & Path, bool recurse)
|
||||
{
|
||||
cout << "Processing folder " << Path.native_file_string() << "\n";
|
||||
directory_iterator end_itr; // default construction yields past-the-end
|
||||
|
||||
for (directory_iterator itr(Path); itr != end_itr; ++itr) {
|
||||
if (recurse && is_directory(*itr)) {
|
||||
// Погружаемся на 1 уровень вниз по дереву каталогов
|
||||
path Deeper(*itr);
|
||||
Process_Files(Deeper, recurse);
|
||||
continue;
|
||||
}
|
||||
// Файл, путь к которому содержится в filename, можно обрабатывать.
|
||||
string filename = itr->file_string();
|
||||
cout << filename << "\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool recurse = true; // обходить ли каталоги
|
||||
Process_Files(current_path(), recurse);
|
||||
return 0;
|
||||
}
|
Binary file not shown.
|
@ -15,7 +15,7 @@ void * Thread( void* pParams )
|
|||
for ( i = 0; i < 5; i++ ) a[ i ] = num;
|
||||
num++;
|
||||
|
||||
//~ struct timespec ts;
|
||||
//~ struct timespec ts;
|
||||
//~ ts.tv_sec = 0;
|
||||
//~ ts.tv_nsec = 10;
|
||||
//~ nanosleep(&ts,NULL);
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,70 @@
|
|||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" void thr_yield(void);
|
||||
|
||||
void thr_yield(void)
|
||||
{
|
||||
printf("thr_yield() called\n");
|
||||
}
|
||||
|
||||
//extern "C" void printf(...);
|
||||
|
||||
struct X {
|
||||
int x;
|
||||
X(int i) {
|
||||
x = i;
|
||||
printf("X(%d) constructed.\n", i);
|
||||
}
|
||||
~X() {
|
||||
printf("X(%d) destroyed.\n", x);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
free_res(void *i)
|
||||
{
|
||||
printf("Freeing `%d`\n", i);
|
||||
}
|
||||
|
||||
char *f2(int i)
|
||||
{
|
||||
try {
|
||||
X dummy(i);
|
||||
pthread_cleanup_push(free_res, (void *)i);
|
||||
|
||||
if (i == 50) {
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
pthread_testcancel();
|
||||
}
|
||||
|
||||
f2(i + 1);
|
||||
pthread_cleanup_pop(0);
|
||||
|
||||
} catch (int) {
|
||||
printf("Error: In handler.\n");
|
||||
}
|
||||
|
||||
return "f2";
|
||||
}
|
||||
|
||||
void *
|
||||
thread2(void *tid)
|
||||
{
|
||||
void *sts;
|
||||
printf("I am new thread :%d\n", pthread_self());
|
||||
pthread_cancel((pthread_t)tid);
|
||||
pthread_join((pthread_t)tid, &sts);
|
||||
printf("main thread cancelled due to %d\n", sts);
|
||||
return (sts);
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
pthread_create(NULL, NULL, thread2, (void *)pthread_self());
|
||||
thr_yield();
|
||||
printf("Returned from %s\n", f2(0));
|
||||
}
|
||||
|
Binary file not shown.
|
@ -12,18 +12,13 @@ static void wait_thread(void)
|
|||
while (time(NULL) == start_time)
|
||||
{
|
||||
/* do nothing except chew CPU slices for up to one second. */
|
||||
//usleep(1);
|
||||
//~ struct timespec
|
||||
//~ {
|
||||
//~ time_t tv_sec; /* секунды */
|
||||
//~ long tv_nsec; /* наносекунды */
|
||||
//~ };
|
||||
|
||||
//~ struct timespec ts;
|
||||
//~ ts.tv_sec = 0;
|
||||
//~ ts.tv_nsec = 10;
|
||||
//~ nanosleep(&ts,NULL);
|
||||
usleep(10000);
|
||||
|
||||
//~ struct timespec ts;
|
||||
//~ ts.tv_sec = 0;
|
||||
//~ ts.tv_nsec = 1000;
|
||||
//~ nanosleep((const struct timespec *)&ts, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,13 +16,7 @@ long_line_behaviour=1
|
|||
long_line_column=72
|
||||
|
||||
[files]
|
||||
current_page=6
|
||||
FILE_NAME_0=472;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/asynch.c;0
|
||||
FILE_NAME_1=328;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/mutexes.c;0
|
||||
FILE_NAME_2=1354;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/semabinit.c;0
|
||||
FILE_NAME_3=642;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/sem08-1a.c;0
|
||||
FILE_NAME_4=2155;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/sem08-1b.c;0
|
||||
FILE_NAME_5=100;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/tmp.c;0
|
||||
current_page=-1
|
||||
|
||||
[build-menu]
|
||||
CFT_00_LB=_Скомпилировать
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,25 @@
|
|||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class foo {
|
||||
public:
|
||||
void *operator *() {
|
||||
return NULL;
|
||||
}
|
||||
void *bar() {
|
||||
return &*this;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
foo f;
|
||||
cout << (unsigned long)f.bar() << endl;
|
||||
cout << (unsigned long)&f << endl;
|
||||
cout << (unsigned long)*f << endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue