Bawnawgwa's Profile User Rating: -----

Reputation: 9 Worker
Active Members
Active Posts:
154 (0.13 per day)
21-January 13
Profile Views:
Last Active:
User is offline Apr 19 2016 03:12 PM

Previous Fields

Dream Kudos:
Icon   Bawnawgwa has not set their status

Posts I've Made

  1. In Topic: Playing simple animation from blender model in monogame?

    Posted 13 Apr 2016

    They said nothing about what to do after you create it. It just showed you how to make it in blender, didn't even talk about exporting it. And all I was finding for doing animations was stuff involving bones, which this has none...........
  2. In Topic: How to utilize multiple threads at once with pthreads?

    Posted 20 Oct 2015

    Haha moving the freeing to my worker thread function did the trick. But yeah I am quite new to thread programming and did not know of the thread pool. I have my thread pool working now and my program works as intended with no seg faults :). I'll need to more carefully debug it and attempt to better understand the thread pool, but right now its holding up haha.

    THank you for the help!
  3. In Topic: How to utilize multiple threads at once with pthreads?

    Posted 20 Oct 2015

    Hmm.... I found a fairly simple thread pool and it was easy to implement. However, I am having trouble now with the freeing of commands[]. With the thread pool and the thread scheduling, commands ends up emptying before it is used by a thread and seg faults. Where would be the best place to free commands[] (or best way?) to avoid that? Here is updated Code:

    struct account{
      pthread_mutex_t lock;
      int value;
    struct arguments{
      pthread_mutex_t comLock;
      char **commands;
      int size;
    struct arguments params;
    struct account *accounts;
    void transaction(void *a);
    int getSize(char** cmds);
    threadpool pool;
    FILE *fp;
    int id = 1;
    int main(int argc, char **argv){
      pthread_t tid_worker[atoi(argv[1])];	
    	int i = 0;
    	//int j = 0;
    	char cmd[1024];
    	params.commands = (char **)malloc(20 * sizeof(char *));
    	char *token;
            params.size = 0;
    	char *path = getenv("HOME");
    	//int id = 1;
    	int j = 0;
    	int end = 0;
    	path = strcat(path, "/Project2/responses.txt");
    	//Create designated worker threads based on user input
    	if(argc == 4){
    	        pool = thpool_init(atoi(argv[1]));
    	        fp = fopen(argv[3], "w");
    		pthread_mutex_init(&params.comLock, NULL);
    		struct account accounts2[atoi(argv[2])];
    		accounts = accounts2;
    		for(j = 0; j < atoi(argv[1]); j++){
    		  pthread_create(&tid_worker[j], NULL, (void*)&transaction, &params);
    		for(j = 0; j < atoi(argv[2]); j++){
    		  pthread_mutex_init(&accounts[j].lock, NULL);
    		while(end != 1){
    			printf("> ");
    			fgets(cmd, 1024, stdin);
    			token = strtok(cmd, " ");
    			while(token != NULL){
    				token[strcspn(token, "\n")] = '\0';
    				params.commands[i] = (char *)malloc(strlen(token)+1);
    				//commands[i] = token;
    				strcpy(params.commands[i], token);
    				token = strtok(NULL, " ");
    			params.size = getSize(params.commands);
    			i = 0;
    			if(strcmp(params.commands[0], "END") == 0)
    				end = 1;
    			printf("< ID %d\n", id);
    			j = 0;
    			if(strcmp(params.commands[0], "END") != 0){
    			  thpool_add_work(pool, (void*)transaction, &params);
    			for(j = 0; j < params.size; j++){
    				params.commands[j] = NULL;
    	return 1;
  4. In Topic: Creating a shell with unique command line in C

    Posted 26 Sep 2015

    That is the assignment. So I need to just scan the input each time and interpret it on my own instead of using argc and argv?

    It is supposed to work like a shell, written in C, that can execute a few basic commands from command line.
  5. In Topic: Binary to Decimal

    Posted 25 Sep 2015

    Yes you must compare characters a[x] == '1' also, you have an if(x = 3). This is probably just a typo haha. But change it to if(x == 3)

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information

Click here to e-mail me


Bawnawgwa hasn't added any friends yet.


Bawnawgwa has no profile comments yet. Why not say hello?