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

Reputation: 9 Worker
Active Members
Active Posts:
151 (0.14 per day)
21-January 13
Profile Views:
Last Active:
User is offline Nov 14 2015 11:43 PM

Previous Fields

Dream Kudos:
Icon   Bawnawgwa has not set their status

Posts I've Made

  1. 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!
  2. 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;
  3. 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.
  4. 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)
  5. In Topic: gl.drawElements out of range error when drawing triangle on canvas

    Posted 10 Sep 2015

    Haha I fixed that because indces[4] was indeed out of range but the error continued. However I believe I got it! My program creates proper images now. All it seemed to take was another gl.bufferData with gl.ARRAY_ELEMENT right above the other bufferData in draw. I was basically just throwing things around when I discovered that :P. Man, that was a frustrating error.

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?