多线程中的单向链表
typedef struct MsgData { SLIST_ENTRY NextEntry;//下一个结点 INT ID; char buff[20]; }STDATA,*PSTDATA; void CtestThreadDlg::OnBnClickedButton17() { PSLIST_ENTRY pListFirstItem,pListItem; PSLIST_HEADER pHead; //创建头结点 pHead = (PSLIST_HEADER)_aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); //初始化头结点 InitializeSListHead(pHead); //新结点数据 PSTDATA stPdata = (PSTDATA)_aligned_malloc(sizeof(STDATA), MEMORY_ALLOCATION_ALIGNMENT); stPdata->ID = 1200; strcpy_s(stPdata->buff, 20,"message"); //添加到队列中,从头添加节点,返回前一个节点 pListFirstItem = InterlockedPushEntrySList(pHead, &stPdata->NextEntry); pListItem = InterlockedPopEntrySList(pHead);//从头部取出数据 PSTDATA pData = (PSTDATA)pListItem; CString str(pData->buff); TRACE(str+_T("\n")); _aligned_free(pListItem);//释放内存 InterlockedFlushSList(pHead); pListItem = InterlockedPopEntrySList(pHead); if (pListItem == NULL) { TRACE(_T("已清空\n")); } _aligned_free(pHead); }
本文标题:多线程中的单向链表
文章链接:http://scyanting.com/article/gcigho.html