-1

I would like to write a simple C console application in windows 8 with VS2013.

For an inter thread communication I have to use a mailbox implementation like this:

#include <stdio.h> 
#include <Rtk32.h> 

RTKMailbox Box; 

void RTKAPI TaskA(void * P) 
{ 
   int i; 

   printf("Task A: waiting at mailbox\n"); 
   RTKGet(Box, &i); 
   printf("Task A: have received number %i\n", i); 
} 

void main(void) 
{ 
   int i; 

   printf("\n"); 
   RTKernelInit(3); 
   Box = RTKCreateMailbox(sizeof(int), 1, "Test Box"); 
   printf("Main  : creating task A\n"); 
   RTKCreateThread(TaskA, 4, 0, 0, NULL, "Task A"); 
   printf("Main  : please enter a number: "); 
   fflush(stdin); 
   scanf("%i", &i); 
   RTKPut(Box, &i); 
   printf("Main  : done.\n"); 
}

Mailbox

Is there a Library for non embedded systems or what would be the best way.

hugo
  • 37
  • 5
  • Here is better description of a Mailbox: http://www.on-time.com/rtos-32-docs/rtkernel-32/programming-manual/module/mailbox.htm – hugo May 22 '15 at 14:27

1 Answers1

0

I'm not sure about a library, but I made a Windows based multi-threaded file copy console example program where one thread reads and the other writes, using a fifo linked list messaging system on top of mutexes and semaphaores. The messaging functions are GetNode() and PutNode() and work with list nodes. Another layer of functions could be added to implement a mailbox like copy interface with ReceiveMessage() and SendMessage(). The linked list could be replaced with a circular array, but the linked list allows for a variable number of messages. I've used a similar linked listed messaging interface for multi-threaded embedded systems and old multi-threaded mini-computer kernels. mtcopy.zip.

rcgldr
  • 27,407
  • 3
  • 36
  • 61